Redirect Users not from Website

Discussion in 'Programming' started by SiteBuyerUK, Feb 13, 2007.

  1. #1
    hey,

    i run a proxy using phproxy 0.52beta and im trying to code into it a way to redirect all people who dont come from the index page while trying to surf, to the index page.

    Ive tried the following in PHP:

    $md5 = $_POST["v"];
    $date =date("m.d.y H");
    $dt = md5($date);

    if($md5 != $dt) {
    header("Location: http://www.radicaloverthrow.com/");
    };

    This is in the surf page i md5 the current date and pass it along in a hidden value with the surf form then check if it is the same and if it isnt redirect however its not working. So is there a way to do it with PHP or htaccess or something?
     
    SiteBuyerUK, Feb 13, 2007 IP
  2. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #2
    Check for $_SERVER['HTTP_REFERER'], but I am not sure about it. If it works please also let us know.
     
    designcode, Feb 13, 2007 IP
  3. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #3
    why not set a session variable on your homepage, then in your header (included in all pages) do a redirect if the session variable isn't set (make sure to do the check AFTER you set the session variable on the homepage)
     
    ccoonen, Feb 13, 2007 IP
  4. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #4
    Great idea ccoonen (y), but it will be valid for one time. Unless you unregister this variable at the end of every page.
     
    designcode, Feb 13, 2007 IP
  5. bscdesign.com

    bscdesign.com Active Member

    Messages:
    681
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #5
    It should be pretty easy. First use split or stripslashes (however in php) to get rid of all the slashes (/) in the $_SERVER['HTTP_REFERER']. Then take out the www. and name the result $referer. Then:

    $allowed = your-site.com;

    if($referer != $allowed) {
    header("Location: http://www.radicaloverthrow.com/");
    };

    I warn you I don't know much php. But I have seen something like this done before.
     
    bscdesign.com, Feb 15, 2007 IP
  6. CBDealer

    CBDealer Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ccoonen's idea is the way to go. $_SERVER['HTTP_REFERER'] isn't that reliable anyway. Set the session var on the index page and redirect from other pages if the var isn't set. Simple, easy, elegant. Way to go, ccoonen.
     
    CBDealer, Feb 16, 2007 IP