The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Return previous page with PHP
dougmanic
post Nov 13 2006, 07:16 PM
Post #1


Newbie
*

Group: Members
Posts: 19
Joined: 3-October 06
Member No.: 320



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Nov 13 2006, 11:15 PM
Post #2


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Nov 13 2006, 11:21 PM
Post #3


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



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.


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Nov 14 2006, 02:24 AM
Post #4


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



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?

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Nov 14 2006, 02:25 AM
Post #5


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Nov 14 2006, 09:45 AM
Post #6


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Peter1968
post Nov 15 2006, 02:20 AM
Post #7


Serious Coder
*****

Group: Members
Posts: 448
Joined: 23-September 06
Member No.: 213



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.

This post has been edited by Peter1968: Nov 15 2006, 02:22 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Curtis
post Dec 28 2006, 06:38 AM
Post #8


Newbie
*

Group: Members
Posts: 11
Joined: 28-December 06
From: California
Member No.: 1,397



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).
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
El-Aurian
post Sep 15 2009, 07:21 PM
Post #9





Group: Members
Posts: 2
Joined: 15-September 09
Member No.: 9,765



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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Curtis
post Sep 15 2009, 08:06 PM
Post #10


Newbie
*

Group: Members
Posts: 11
Joined: 28-December 06
From: California
Member No.: 1,397



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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
El-Aurian
post Sep 16 2009, 07:36 PM
Post #11





Group: Members
Posts: 2
Joined: 15-September 09
Member No.: 9,765



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

This post has been edited by El-Aurian: Sep 16 2009, 07:37 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Sean - Bedroom Coder
post Oct 7 2009, 10:51 AM
Post #12





Group: Members
Posts: 1
Joined: 7-October 09
Member No.: 9,955



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 post has been edited by Sean - Bedroom Coder: Oct 7 2009, 10:57 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Jim8974
post Dec 28 2009, 01:37 PM
Post #13





Group: Members
Posts: 1
Joined: 28-December 09
Member No.: 10,700



Hi,

I am trying to create a similar process to automatically create the previous page, you can take this method as far as you want really and the limit of the number of back pages you can go to is only set by how much work you want to add to it.

for this example I will only use the previous page.

okay firstly you need to create two session variables.

Current page

Previous page.

give current page the value of the current page, and test to see if previous page has been set, if it hasnt then it means that its the first visit.

if it is the first visit give previous page a default value.

now when the user changes page the order of this is important as it defines the page links.

take the Current Page Session value and give this to 'Previous Page' and change Current Page Session Value to the ... welll current page name.

You now have two values held in session.

the value of the current page, and the value of the previous page. you can use these in links to provide returns to any drill downs that you have done, (that is of course if you extend it to 2nd previous page 3rd previous page etc.

However there are a LOT of limits to this.

Firstly it will only work on your own site/code as you will only be able to the code withint your own site.


Secondly, its limited past a two page history as once you have lost the 3rd lastr page you can end up going round in circles

(e.g open page 1 go to page 2, go back using script to page one, the previous page is now page 2, if you use the link again, the previous page is now page 1 etc etc etc.)



hope this helps you or can give you a rough idea of a better script.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
geilt
post May 13 2011, 11:32 AM
Post #14





Group: Members
Posts: 1
Joined: 13-May 11
Member No.: 14,541



Thanks very much for this helpful description. It helped me create the following. I am making an admin nav in Wordpress and the following solution worked for me.

In order to overcome this problem I did the following:

CODE

    <?php
    session_start();
    if($_REQUEST['page'] != $_SESSION['oldPage'])
        $_SESSION['oldURL'] = $_SESSION['newURL'];

    $_SESSION['oldPage']     = $_REQUEST['page'];
    $_SESSION['newURL']     = $_SERVER['REQUEST_URI'];    
    ?>

So you see I am checking to make sure that the current page does not equal the old page (in the case of a page refreshing itself to update an option for example).

If its not equal then we change the oldURL to the newURL so that it stores the proper last page. We do not want o ochange the oldURL if we are on the same page.

Then we set a session variable called oldPage to the query value of "page" to check on the next page. We finalyl set the current full page to newURL so that we can pass it to old URL on the next page (if its a different page).

A valid example of a link going back to previous would be

CODE

    <?php
    $lastLink    = "<a href='" . $_SESSION['oldURL'] . "'>Back to Previous Page</a>";
    ?>


It works, and it works well, though thinking about it still confuses the hell out of me!

This post has been edited by geilt: May 13 2011, 11:34 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Ephraim F. Moya
post May 14 2011, 02:37 PM
Post #15


Advanced Member
****

Group: Members
Posts: 167
Joined: 2-September 07
From: New Mexico
Member No.: 3,702



It seems to me that you guys are on a fools errand.

None of the 'solutions' you have described include the current user. I assume that your aim is to keep records about each individual user. None of the posts even mentions that.

So I think what you'll end up with is some kind of random path for a random number of visitors.

The big boys keep a record of each individual page an individual visitor sees in a whole other database table by guest id number.

Since most modern browsers throw away cookies whenever the browser is closed the methods described fail overnight.

This post has been edited by Ephraim F. Moya: May 14 2011, 02:39 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 01:53 AM