Page 1 of 1

referring page with variables

Posted: Fri Mar 30, 2007 4:50 pm
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?

Posted: Fri Mar 30, 2007 4:53 pm
by feyd

Posted: Fri Mar 30, 2007 5:42 pm
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.

Posted: Fri Mar 30, 2007 6:41 pm
by nickvd
basename(__FILE__) is safer than PHP_SELF.