PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Mon Apr 25, 2005 9:07 am
I want to add one variable to the end of the page's current url.
I thought of doing:
Code: Select all
<a href="e;<?PHP echo $_SERVERї'PHP_SELF']?>?variable"e;>link</a>
That works great in all cases except when the current url is something like:
http://www.url.com/start/index.php?ID=7
The first problem is that $_SERVER['PHP_SELF'] will not return the "?ID=7" part.
The second problem is that, even if it did, the final url would be:
http://www.url.com/start/index.php?ID=7?variable
That doesn't make sense either.
Is there a workaround so that PHP_SELF returns the part after the ? as well?
hongco
Forum Contributor
Posts: 186 Joined: Sun Feb 20, 2005 2:49 pm
Post
by hongco » Mon Apr 25, 2005 10:07 am
try this: $_SERVER['QUERY_STRING']
phpScott
DevNet Resident
Posts: 1206 Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.
Post
by phpScott » Mon Apr 25, 2005 10:42 am
first of all you have some quote issues with your the code you posted
Code: Select all
<a href="<?PHP echo $_SERVER['PHP_SELF']?>?variable">link</a>
try
Code: Select all
<a href="<?php echo $_SERVER['PHP_SELF'];?>?someVar=<?php echo $var; ?>">somelink</a>
as it seems to be following your pattern.
at the top of your page you will likely have to use
to retrieve the value
bytte
Forum Commoner
Posts: 75 Joined: Sun Nov 23, 2003 8:20 am
Location: Belgium
Post
by bytte » Mon Apr 25, 2005 10:48 am
I can't do that since the code is in my header that re-appears on every page.
There's different variable names and values passed on different sections on my site.
Actually, I use the code to switch to another CSS file.