1,105,644 Community Members

URL variables

Member Avatar
fheppell
Junior Poster
127 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
pritaeas
mod_pritaeas
11,335 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

You'll need some scsripting to do this. I don't think it's possible with plain HTML.

Member Avatar
fheppell
Junior Poster
127 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Didn't think it would be. Any ideas how?

Member Avatar
pritaeas
mod_pritaeas
11,335 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 

What do you want to use, Javascript, PHP, something else?

Member Avatar
fheppell
Junior Poster
127 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Prefrably javascript but PHP would be fine

Member Avatar
EvolutionFallen
Posting Pro
504 posts since Aug 2009
Reputation Points: 107 [?]
Q&As Helped to Solve: 108 [?]
Skill Endorsements: 8 [?]
 
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>
Member Avatar
fheppell
Junior Poster
127 posts since Mar 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks!

Question Answered as of 1 Year Ago by pritaeas and EvolutionFallen
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: