How to get the previous url using PHP
Use the $_SERVER['HTTP_REFERER']
header, but bear in mind anybody can spoof it at anytime regardless of whether they clicked on a link.
How to obtain two previous page's URL in php
Do what other people have done:
First solution:
Create a hidden
field in your pages so that when a user clicks on login
it will take him to the login.php
page with the previous link. Then you can do anything you want (like, saving it to $_SESSION['url']
) with this link.
Second Solution:
Imagine you have an anchor like this:<a href="login.php">login</a>
.
Instead of using just login.php
you can use login.php?redirect_to=http://example.com/post/1
so that you can access the url from your login.php
page with a $_GET['redirect_to']
request.
NOTE: Always remember to sanitize user input data.
Get previous URL path in PHP
$previous_page = $_SERVER['HTTP_REFERER'];
$path_parts = pathinfo($previous_page);
$result = $path_parts['basename']; //index.php
https://www.php.net/manual/en/function.pathinfo.php
PHP get previous page url after redirect
I believe what you want is called breadcrumbs.
What to use for navigation chain storage is actually up to you. You might use even $_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 alot of samples and snippets using keyword breadcrumbs
.
On the topic of saving last visited location (the way to determine wether abonent 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.
How can I get previous Site URL using PHP
Ultimately you have to rely on the user and their browser configuration.
If they clicked on a link from another site and the user doesn't have anything (plugins, etc.) blocking the referrer, $_SERVER['HTTP_REFERER']
will be populated.
If they visited the site directly or they are blocking HTTP_REFERER
the value will be blank and there's no way for you to access it.
How to get previous page url in codeigniter
try this:
$this->load->library('user_agent');
if ($this->agent->is_referral())
{
$refer = $this->agent->referrer();
}
In this way you load user_agent
library, check if there is a referral url and then store It into a variable to use It after
Go Back to Previous Page
You can use a link to invoke history.go(-1)
in Javascript, which is essentially equivalent to clicking the Back button. Ideally, however, it'd be better to just create a link back to the URL from whence the user was posted to the form - that way the proper "flow" of history is preserved and the user doesn't wonder why they have something to click "Forward" to which is actually just submitting the form again.
Related Topics
Laravel Multiple Pagination in One Page
Php: Inserting Values from the Form into MySQL
How to Find the Date of a Day of the Week from a Date Using PHP
Ternary Operator Left Associativity
How to Check If Curl Is Enabled or Disabled
Laravel: Validate an Integer Field That Needs to Be Greater Than Another
How to Generate Random Date Between Two Dates Using PHP
Calling C/C++ Library Function from PHP
Create Programmatically a Variable Product and Two New Attributes in Woocommerce
How to Convert Output of Number_Format Back to Numbers in PHP
Convert Flat Array to the Multi-Dimensional