Im trying to create some links depending on the GET parametre currently set.
My URL looks like this:
http://mysite.com/index.php?bar=test&page=page
In my code I do the following:
$bar = $_REQUEST['bar'];
<a href="index.php?bar=<?php echo $bar?>&page=anotherpage"
But every time I click the link, it adds the whole string to the URL again.
Like first click would give me this URL:
http://mysite.com/index.php?bar=test&page=anotherpagepage=anotherpage
And next click creates:
http://mysite.com/index.php?bar=test&page=anotherpagepage=anotherpagepage=anotherpage
And so on.
Is there any way to only get the request once so that the URL always looks like this:
http://mysite.com/index.php?bar=test&page=anotherpage
No matter how many times I click the link?
Thanks a lot!
You missed an ampersand in your first example. (&). Give this a try:
Or even better, escape your variables before use to prevent XSS, Cross Site Scripting security vulnerability. Use
urlencode()for URLs.http://nl.php.net/manual/en/function.urlencode.php: