Help - Search - Members - Calendar
Full Version: Return previous page with PHP
HTMLHelp Forums > Programming > Server-side Scripting
dougmanic
Is there a possible way to store the user's previous page history in a variable using PHP?

I tried $_SERVER['HTTP_REFERER'], but nothing shows up.
Brian Chandler
QUOTE(dougmanic @ Nov 14 2006, 09:16 AM) *

Is there a possible way to store the user's previous page history in a variable using PHP?

I tried $_SERVER['HTTP_REFERER'], but nothing shows up.


Simply, and strictly, no there isn't. The php program is running on a server; the "history" is a property of a browser that has issued an HTTP request to the server - there is no way for the php program to "know" anything about the browser except what was contained in the HTTP request.

So yes, there may be a 'refer®er' header, but you can't rely on that.

But what are you _actually_ trying to do?
Brian Chandler
QUOTE(Brian Chandler @ Nov 14 2006, 01:15 PM) *


....

So yes, there may be a 'referŽer' header, but you can't rely on that.

....



Admins: Pleeeease switch this idiotic nonsense off! Please give us a board like the old htmlhelp board where the software was written by intelligent people with the intent of being useful, instead of by total morons.


Peter1968
QUOTE(dougmanic @ Nov 14 2006, 11:16 AM) *

Is there a possible way to store the user's previous page history in a variable using PHP?

I tried $_SERVER['HTTP_REFERER'], but nothing shows up.


In short, PHP is server-side, the browser's history is client-side, and never the twain shall meet. PHP, as a server function, doesn't have a clue what the user's browser is about. Makes sense when you give it some thought, doesn't it?

Peter1968
QUOTE(Brian Chandler @ Nov 14 2006, 03:21 PM) *


Admins: Pleeeease switch this idiotic nonsense off! Please give us a board like the old htmlhelp board where the software was written by intelligent people with the intent of being useful, instead of by total morons.


Referer
Referrer

*shrug* What are exactly you typing in? What idiotic nonsense?
Brian Chandler
QUOTE(Peter1968 @ Nov 14 2006, 04:25 PM) *

QUOTE(Brian Chandler @ Nov 14 2006, 03:21 PM) *


Admins: Pleeeease switch this idiotic nonsense off! Please give us a board like the old htmlhelp board where the software was written by intelligent people with the intent of being useful, instead of by total morons.


Referer
Referrer

*shrug* What are exactly you typing in? What idiotic nonsense?


The sort of moronic nonsense you get with "Office" software, until you find out how to switch it all off, that interferes with what you type. You type 'fish' and the software thinks you must have meant to type 'bacon', that sort of thing. In this case I wrote arr-ee-eff-ee-leftparenthesis-r-rightparenthesis-r-e-r, which is what I meant to write, because I am more intelligent than this moronic software, but the software changed it as above. (The point is that "referrer" is misspelled in the HTTP specification.)

I suppose the heroic thing to do would be to write an intermediating page that allows you to type, and works out what needs to be submitted to the moron software to get it displayed without being messed up.
Haven't time just at the moment.
Peter1968
referŽer

Edit: I see what you're saying. To be honest, I don't recall a setting inside of IPB that'll disable such "smart tagging". Mind you, I used an earlier version, when it was still free.
Curtis
Lol, that seems like a waste of programming, imo. It should just let people type the hex entities for stuff like that.

Also, as for the server side never getting a hold of the history, that will always be so because of security/privacy issues. However, you can get pretty close when asynchronous scripting (ajax).
El-Aurian
Sorry, for resurrecting an old thread.

But i was hoping to use the variable to detect whether someone has accessed a php page, using a page on my website. to try and prevent hackers from accessing the scripts.

Is $_SERVER['HTTP_REFERER'], the best option for this?

Thanks,

Matthew Millar
Curtis
That's the wrong way to go about security. What are you really trying to accomplish?

In any case, if you read this thread, you should see that such information from the client is unreliable, at best.
El-Aurian
I'm hoping to detect the previous page, so i can tailor what is displayed by the php, dependent on which page the user came from.

Security isn't a huge issue, i was just thinking ahead as to how i could secure it.

I'm aware that i can just add an extra hidden input into the form, but i was hoping to avoid dirtying the referrer pages, if there was a way of detecting the previous page using php.

Thanks,

Matthew Millar
Sean - Bedroom Coder
QUOTE(El-Aurian @ Sep 16 2009, 07:36 PM) *

I'm hoping to detect the previous page, so i can tailor what is displayed by the php, dependent on which page the user came from.

Security isn't a huge issue, i was just thinking ahead as to how i could secure it.

I'm aware that i can just add an extra hidden input into the form, but i was hoping to avoid dirtying the referrer pages, if there was a way of detecting the previous page using php.

Thanks,

Matthew Millar


Im trying to find a better way of doing this just to provide a link to the previous page, but currently using this method below

I am using a link

<a href="<?=$_SESSION['previous_page']?>">Previous Page</a>

and then this called in at the bottom of the page after the link
$_SESSION['previous_page']=htmlentities($_SERVER['REQUEST_URI']);

To then decide what was to be displayed on the page you could set up a switch, you could also use $_SERVER['QUERY_STRING'] and pass through a query on the forms action url,

Of course its not fool proof and the very reason I am now trawling the net trying to find a better way, but it sets a session variable of the last page viewed from any page you set the session.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.