How can I detect all pages in a redirect using php?

I found this question on quora and did not know how to resolve it

Script -

The user is on one.php and clicks a link that points to two.php

Two.php redirects the header to tr.php

If we check the link URL for three.php $ _SERVER, display one.php instead of two.php

How do we know that two.php was an intermediate page that redirected the header?

Note that I cannot do anything with one.php or two.php, which can include any parameters indicating that two.php is included in the redirect

+4
source share
4 answers

Save Session Record

You can save the stack in a session variable. Just keep unshifting the values ​​at $_SESSION["history"] , removing elements from the end of the array when the collection grows to a certain size.

For instance:

 // Need to do this if we wish to store data session_start(); // Set the history array if it doesn't exist isset( $_SESSION["history"] ) || $_SESSION["history"] = array(); // Push current URI onto history array_unshift( $_SESSION["history"], $_SERVER["REQUEST_URI"] ); // Prevent history from exceeding 5 values array_splice( $_SESSION["history"], 5 ); 

Download it to all PHP files

This should be added at the beginning of each file or in the global header template, if you have one. Alternatively, if you decide, you can download it globally with auto_prepend_file :

Specifies the name of the file that is automatically parsed before the main file. The file is included as if it were called using the require function, so include_path is used. - Documentation

View the story

You can show the whole story by referring to $_SESSION["history"] :

 // Output history array var_dump( $_SESSION["history"] ); 
+3
source

Since you do not have access to one.php or two.php, there are no workarounds. Since two.php provided a redirect, the browser passes the referrer masking two.php. This is not specified in the RFC, but it is an agreement in the clients.

If you have access, you can pass the referrer URL in the request, still using 301. Adding a hash or signature can be used to verify the URL.

+1
source

You can use sessions or cookies. You would like to mark records with time and only consider those records with very close time stamps.

0
source

You can use GET parameters in redirection from two.php to three.php.

So in two.php:

header ('Location: three.php? source = two.php');

and then in three.php you check $ _GET ['source'];

-1
source

Source: https://habr.com/ru/post/1415443/


All Articles