0

Let's say a user goes to example.com/example.html?one=foo
How could I make a link so that it appends another url variable like: example.com/example.html?one=foo&two=bar
I've tried <a href="?two=bar">Click here</a> but that just replaces the existing variable with a new one

How could I do this?
Thanks in advance

3
Contributors
6
Replies
22
Views
4 Years
Discussion Span
Last Post by fheppell
0

You want a link that links back to the same page, but with an extra variable tacked on? Did I understand correctly?

<?php 
    $thisPage = htmlentities($_SERVER['PHP_SELF']);
    $hasVar = strpos($thispage, '?');
    if($hasVar === FALSE)   // Check if there is already a variable on the URL
        $url = $thisPage . '?two=bar';  // if not, use ? to start query string
    else
        $url = $thisPage . '&two=bar';  // if yes, use & to append variable
?>
<a href="<?php echo $url; ?>">link</a>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.