Page 1 of 1

HEADER Location: ? Problem

Posted: Wed Feb 23, 2011 12:02 pm
by tdmrider
Hi.
Re php code: header ("Location: reports/ppid.php?txnid=$txnid&delete=1"); which sits at the completion of a script.
This works fine if I want to go to 'reports/ppid.php'. Unfortunately, the script can be called by any number of different pages.
How do I go back 1 page (or maybe 2 come to that)?
It's easy with a manual link and javascript - but I can't find a way to incorporate js with the Get data '?txnid=$txnid&delete=1'.
I have tried all ways with $_SERVER['HTTP_REFERER'] - but with no luck.
Any suggestions would be much appreciated.
Hope I have explained well enough.
Thanks
TdmRider

Re: HEADER Location: ? Problem

Posted: Wed Feb 23, 2011 2:42 pm
by pickle
So basically you want some way to say "Return to the place that sent you here"?

There are 2 ways I can think of:

1) On every page, set a variable in $_SESSION like $_SESSION['last_page'] = 'somepage.php'. Then, on this ppid.php page, read that variable & send them back there.
2) On every page that links to this page, put something in the URL like: ppid.php?return_to=somepage.php. Then in ppid.php, read $_GET['return_to'], and forward the user there.

Also, as a sidenote, when you use the Location: header, you're supposed to provide the full URL (ie: http://yourwebsite.com/reports/ppid.php?..etc). In most cases providing a relative URL like you've done will work, but full URLs is a good practice to get into.

Re: HEADER Location: ? Problem

Posted: Wed Mar 02, 2011 1:02 pm
by tdmrider
Thanks Pickle .. Much appreciated. Sorry I am so late with the thnx ... getting old!