Need a short script

Discussion in 'PHP' started by Ripped, Nov 16, 2008.

  1. #1
    I need a short script that will recognize if the traffic for a site is a type-in traffic (i.e if the user accessed the page by typing the URL directly in the browser), or the traffic is referred from another website.

    So this is what it needs to do


    If (traffic == typein)
    Redirect to www.website1.com

    Else
    Redirect to www.website2.com
     
    Ripped, Nov 16, 2008 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    <?
    
    if (isset($_SERVER['HTTP_REFERER']))
     header("Location: http://www.website1.com",true,301);
    else
     header("Location: http://www.website2.com",true,301);
    
    ?>
    PHP:
     
    wmtips, Nov 16, 2008 IP
  3. Zeras

    Zeras Guest

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Based on his request order, it should be !isset ..

    -Zeras
     
    Zeras, Nov 16, 2008 IP
  4. Ripped

    Ripped Well-Known Member

    Messages:
    2,151
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #4
    thanks a lot guys, that did the trick just fine!
     
    Ripped, Nov 16, 2008 IP
  5. Ripped

    Ripped Well-Known Member

    Messages:
    2,151
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #5
    Actually I forgot to mention that I wanted to do a frame redirect, I used my lousy PHP skills and html coding to come up with this code, I have some syntax error in the PHP coding probably so when the file is executed is shows blank.

    
    <?
    
    if (isset($_SERVER['HTTP_REFERER']))
    {
     
    
    
    echo '
    <frame src="www.website1.com" name=mainwindow frameborder=no framespacing=0 marginheight=0 marginwidth=0>
    </frame></frameset>
    
    <noframes> ';
    
    
    header("www.website1.com",true,301);
    
    echo '</noframes>';
    
    }
    
    
    else
    {
     
    
    
    echo '
    <frame src="www.website2.com" name=mainwindow frameborder=no framespacing=0 marginheight=0 marginwidth=0>
    </frame></frameset>
    
    <noframes> ';
    
    
    header("www.website2.com",true,301);
    
    echo '</noframes>';
    
    }
    
    ?>
    PHP:
    Could you tell me what's wrong with the code
     
    Ripped, Nov 16, 2008 IP
  6. newgenservices

    newgenservices Well-Known Member

    Messages:
    862
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    105
    Digital Goods:
    1
    #6
    Please try

    
    <?php
    
    if (isset($_SERVER['HTTP_REFERER']))
    {
    echo '<iframe scrolling="no" frameborder="0" src="http://www.website1.com"></iframe>';
    } else {
    echo '<iframe scrolling="no" frameborder="0" src="http://www.website2.com"></iframe>';
    }
    
    ?>
    
    Code (markup):
     
    newgenservices, Nov 17, 2008 IP
  7. Ripped

    Ripped Well-Known Member

    Messages:
    2,151
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #7
    Thanks a lot, this code works, meaning it executes, however, the iframe is messed up and the website isn't displayed properly, I guess the webpage should be framed in different way, any ideas?
     
    Ripped, Nov 18, 2008 IP
  8. newgenservices

    newgenservices Well-Known Member

    Messages:
    862
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    105
    Digital Goods:
    1
    #8
    You can name the iframe, set width and heights and also use id and make use of css. If you can post up a screenshot or a URL, i can check and help you.
     
    newgenservices, Nov 18, 2008 IP
  9. harrisunderwork

    harrisunderwork Well-Known Member

    Messages:
    1,005
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    135
    #9
    Why r u using frames when you want to redirect to some website ?
     
    harrisunderwork, Nov 18, 2008 IP