2

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:

  • URL Manipulation
  • Cookie
  • Session
  • Any kind of Variables
  • Absolutely no changes to Page1.php

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.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
baburao113
  • 785
  • 2
  • 8
  • 12

3 Answers3

1

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.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
  • Thank you, but Tell me the possibility of detecting a redirected visitor on Page2.php Without Doing/Using: URL Manipulation, Cookie, Session, Any kind of Variables. And in Any Server-side or Client-side language.........? Absolutely doing no changes to Page1.php – baburao113 Mar 09 '12 at 21:29
1

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?

Community
  • 1
  • 1
Rémi Breton
  • 4,209
  • 2
  • 22
  • 34
  • Thank you but tell me the possibility of detecting a redirected visitor on Page2.php Without Doing/Using: URL Manipulation, Cookie, Session, Any kind of Variables. And in Any Server-side or Client-side language.........? Absolutely doing no changes to Page1.php – baburao113 Mar 09 '12 at 21:29
1

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.

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
Ray
  • 40,256
  • 21
  • 101
  • 138
  • +1 Probably the best way. Query strings and cookies do not promote integrity, but cookies are better. I'm always baffled when people post things like "I don't want to use sessions", it suggests that they don't understand *how* to use the session, not that they considered it and decided it wasn't the right solution. – Wesley Murch Mar 09 '12 at 21:16
  • Tell me the possibility of detecting a redirected visitor on Page2.php Without Doing/Using: URL Manipulation, Cookie, Session, Any kind of Variables. And in Any Server-side or Client-side language.........? Absolutely doing no changes to Page1.php – baburao113 Mar 09 '12 at 21:27
  • @baburao113: Why, pray tell, are you avoiding all the basic built-in tools of your chosen programming language that would make this extremely simple? Seriously, what are you expecting: magic? – Wesley Murch Mar 09 '12 at 21:29
  • @Madmartigan lol!! :P I'm not avoiding anything. I just want to know if it's possible to detect the visitor which lands on Page2.php without doing extra work to do any modifications in Page1.php That's it... I'm asking this because I don't want other sites to detect that I have redirected users to their website. May be I wasn't clear enough, or may be my english is bad :P – baburao113 Mar 09 '12 at 21:49
  • You should have just asked your real question to begin with. You want to redirect users and keep it secret from the external site you redirect to? You can't really (access logs will show it). Why do you want to, or why do you feel you have to? – Wesley Murch Mar 09 '12 at 21:56
  • @Madmartigan I'm sorry about that. Can you please explain it more clearly? What do you mean by Access Logs? How can they access it exactly? And what about if I redirect Page1.php to Page2.php in my own site and if I use Google Analytics in only Page2.php and not in Page1.php, will Google ever know that I have redirected that particular visitor? – baburao113 Mar 09 '12 at 22:41