Storing current page and go-back to it later

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Storing current page and go-back to it later

Post by CoderGoblin »

Hello All,

In the past I have had situations where I needed to move to another URL (with a form handling validation) and then go back to the original page.

Example
url1 - Link to url2 (i.e modify contact details)
url2 - contains form
url2 - posted values - validate - upkeep database - header (location=url).

To perform this I normally use $_SERVER['HTTP_REFERRER'] and passed that into url2. url2 retains that value through the post and knows when the form is correct to move to back.

I have recently been told that proxies can fool/confuse this methodology.

What are the preferred/alternative methods of achieving this functionality. No cookies/javascript/session saving unfortunately (due to legacy/customer requirements)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Well you method is correct, its just that its an optional header and so you cant always rely on it holding the page. You need to do what you currently do except pass url2 the value of url1 in the link/button to url2.

Never just rely on something, always check and ensure it.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

[Solved] Storing current page and go-back to it later

Post by CoderGoblin »

Thanks kettle_drum. That's what I thought someone would say... Really wanted to avoid passing the url but will do it that way unless someone comes up with a better idea.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Well you will always be technically passing the url as that is what happens to get the url in the http_referrer variable. If you dont want the user to physically see it in the URL (which is probably the case - as it will make the URL look messy), place the URL in a session or cookie each time a page is loaded and then on the next page read this value before you replace it with the page just loaded details.

Its easy enough to do, the user doesnt see it, and it will ensure that the value is always present and correct.
Post Reply