Click here to Skip to main content
15,611,367 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
how can i find previous visited url in php? i can find current visited url using this piece of code($_SERVER['HTTP_REFERER']). But i need to find last visited page url.

What I have tried:

JavaScript
$_SERVER['HTTP_REFERER']
Posted
Updated 18-Feb-22 5:35am
Comments
Suvendu Shekhar Giri 25-Oct-16 9:48am    
What's issue with $_SERVER['HTTP_REFERER']?
It should give the last visited url, isn't it?

You are wanting to bypass browser security. If what you wanted to do was permitted than any page you go to could gather a great deal of personal information from you with you knowing or being able to stop it. Your browsing history is personal information. And valuable as a commodity.

You are allowed to get the referrer - and that's something allowed because it is often necessary - and basically happens anyway: the referrer's arguments, for example, need to be parsed and picked up in case data is being passed between pages (common practice) by the web developer.

Somewhat related - you cannot open a file on the client directly (by path and filename). The routines always require a popup and user interaction to prevent some very bad security consequences.
 
Share this answer
 
I believe what you want is called BREADCRUMBS.

What to use for navigation chain storage is actually up to you. You might even use
$_SERVER['HTTP_REFERER']
if you want, but that'd be unreliable as it's client-side. Usual way to store such chain is actual URI or session.

For example, you have such URI: http://www.example.com/post_manager/post

Then you can iterate through explode(
"/", $_SERVER["REQUEST_URI"]
) to get each step.

That's basic explanation to guide you to a right direction. You can google a lot of samples and snippets using keyword breadcrumbs.

On the topic of saving last visited location (the way to determine whether auser came from manager or homepage): you can use session's variables to do that. Here's an example:

This way you can set a variable on your homepage:

<?php
    session_start(); 
    $_SESSION['previous_location'] = 'homepage';
?>

And then you just access it from another page:

<?php
    $previous_location = $_SESSION['previous_location'];
?>

It's important to set session.save_path in your PHP configuration file or your sessions might get lost.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900