Reputation: 815
Here is the scenario:
Visitor of Page1.php is being redirected with JavaScript to Page2.php
Is there a way to know that visitor which lands on Page2.php is a redirected visitor by monitoring Page2.php if I don't use any sessions and variables at all in any language?
Without Doing/Using:
I'm asking this because I don't want other sites to detect that I have redirected users to their website.
I just want to know the possibility.
Upvotes: 2
Views: 305
Reputation: 41428
Set a javascript cookie on the initial page when you do the redirect.
On the new page, check to see if the cookie is set, then delete it.
Upvotes: 1
Reputation: 4259
If you don't want to use server-side languages, your only alternative is JavaScript
. You could redirect to Page2.php?redirected=true
and use the following code to GET
the redirected variable on Page2.php
.
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
if($_GET['redirected']){
// Redirected from Page1.php!
}
Source: how to get GET and POST variables with JQuery?
Upvotes: 1
Reputation: 102745
Just set a flag in the query string when you redirect (append the query string to your redirect location):
Page2.php?redirect=1
Or if you need the referring page:
Page2.php?referer=Page1.php
Then check with $_GET['referer']
You might be able to read the $_SERVER['HTTP_REFERER']
, but I personally tend to avoid it because it doesn't always contain what you think it should.
Upvotes: 1