A little help please... reload/refresh if referrer is from=?

Discussion in 'PHP' started by n00bl3t, Mar 23, 2013.

  1. #1
    hello,

    Does anybody give me an idea how to make this happen?

    I know about this little script:

    <metahttp-equiv="refresh"content="10;url=http://example.com"/>

    but I want to add a little script before this is loaded.

    I only want the url to refresh IF the referrer is from www.123.com..

    so this is the scenario:

    if visitor A goes into www.xyz.com and he/she is coming from search engine the refresh code above will not load...

    if visitor B goes into www.xyz.com and he/she is coming from www.123.com the refresh/reload code above will kick in..

    Any help is very much appreciated...
     
    n00bl3t, Mar 23, 2013 IP
  2. Gemba

    Gemba Member

    Messages:
    36
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    25
    #2
    You can use the $_SERVER['HTTP_REFERER'] variable

    if (stripos($_SERVER['HTTP_REFERER'], "123.com")) {
    header('Location: http://redirect.com');
    }
    Code (markup):
    redirect.com being the place you want to redirect to and 123.com being the referrer you're looking for.
     
    Gemba, Mar 23, 2013 IP
  3. n00bl3t

    n00bl3t Well-Known Member

    Messages:
    383
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Hi Gemba,

    I think the code you have create makes "DIRECT" refresh/reload of the page? I wanted the 10seconds wait time before it reload/refresh... is this possible?
     
    n00bl3t, Mar 23, 2013 IP
  4. Gemba

    Gemba Member

    Messages:
    36
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    25
    #4
    Yeah, just change the 2nd line to

    echo '<metahttp-equiv="refresh"content="10;url=http://example.com"/>';
     
    Gemba, Mar 23, 2013 IP
  5. n00bl3t

    n00bl3t Well-Known Member

    Messages:
    383
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #5
    for example:
    Scenario ONE:
    visitor A came from xyz.com (REFERER) and went to 123.com/home.html

    now that xyz.com is the referer.... I want the visitor A to see 123.com/home.html then after "X" seconds Visitor A gets redirected to 123.com/latest_news.html

    Scenario TWO:

    Visitor B came from unknownreferer.com (NOT WANTED REFERER) and went to 123.com/home.html

    nothing will happen or NO redirect/reload/refresh will happen to VISITOR B.... Visitor B can either leave the site or browse or do whatever...
     
    n00bl3t, Mar 23, 2013 IP
  6. n00bl3t

    n00bl3t Well-Known Member

    Messages:
    383
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #6
    I see... uhmmm a little problem... how do I insert this as a whole code? in header.php ?
     
    n00bl3t, Mar 23, 2013 IP
  7. Gemba

    Gemba Member

    Messages:
    36
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    25
    #7
    Yes. Wherever your <head> tags are in your PHP files.
     
    Gemba, Mar 23, 2013 IP
  8. n00bl3t

    n00bl3t Well-Known Member

    Messages:
    383
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    120
    #8
    Hi Gemba,

    I was not successful in implementing the code. However, I found this:

    http://wordpress.org/extend/plugins/referrer-detector/screenshots/

    I wanted something like this, but that plugin was only able to post welcome messages... what I wanted is to execute a script if the url is from one of the list I create...

    Anyway thank you so much for giving me some information.
     
    n00bl3t, Mar 23, 2013 IP
  9. webdeveloperindia

    webdeveloperindia Active Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    73
    #9
    Try to add \(back slash) before "(quote) e.g.
    if (stripos($_SERVER['HTTP_REFERER'], "123.com")) {
    echo '<metahttp-equiv=\"refresh\"content=\"10;url=http://example.com\"/>';
    }


    Hope this will help!
     
    webdeveloperindia, Mar 24, 2013 IP
  10. Gemba

    Gemba Member

    Messages:
    36
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    25
    #10
    Backslash for quotes aren't needed when it's enclosed by a single quote.
     
    Gemba, Mar 24, 2013 IP
  11. webdeveloperindia

    webdeveloperindia Active Member

    Messages:
    90
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    73
    #11
    Thats right
    I always use double quotes so, this is my practice.
    Anyways did you got the solution?
     
    webdeveloperindia, Mar 24, 2013 IP