referring page with variables

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

Post Reply
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

referring page with variables

Post by andym01480 »

I have written a calendar script that passes variables in the url to select previous and next months.
eg calendar.php?m=1177968595

To make it embeddable in other scripts I've tried

Code: Select all

$url=$_SERVER['HTTP_REFERER'];
echo  "<a href=\"$url?style=blog&m=$previous\">Previous</a>";
which is okay the first time

Code: Select all

index.php?style=blog&m=1177968595
The next time it will append the variables to that url.

Code: Select all

http://localhost/secure/calendar/index.php?m=1173392529&style=blog&pageid=16?style=blog&m=1168294929
The other problem is that it doesn't pass on other variables like say pageid=17

So how do I reliably pick on the referring page and its variables and then put them with the extra variables into a link? Is there a function I have missed or do I need do some serious coding?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

Thanks for the pointer Feyd - quick as ever.
It got me looking in the right place in the manual.

I think I'm going to use...

Code: Select all

$filename=basename($_SERVER['PHP_SELF']); //to grab the name of the script
parse_str($_SERVER['QUERY_STRING'],$vars) ; // to put all the variables in an associative array
Then I can build the link by changing the variables that should be there and appending them to the filename.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

basename(__FILE__) is safer than PHP_SELF.
Post Reply