HEADER Location: ? Problem

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
tdmrider
Forum Newbie
Posts: 8
Joined: Mon Dec 27, 2010 10:29 am

HEADER Location: ? Problem

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: HEADER Location: ? Problem

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
tdmrider
Forum Newbie
Posts: 8
Joined: Mon Dec 27, 2010 10:29 am

Re: HEADER Location: ? Problem

Post by tdmrider »

Thanks Pickle .. Much appreciated. Sorry I am so late with the thnx ... getting old!
Post Reply