Sending people to specific pages that are coming from specific pages...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cemlouis@gmail.com

    #1

    Sending people to specific pages that are coming from specific pages...

    Hi,

    I want to show some specific pages to people that comes to my site from
    specific urls, I know the variable $_SERVER['HTTP_REFERER'] will be
    used but how?

    For ex if the visitor comes from a site that is like:


    cominghost.com
    www2.cominghost .com

    I want to send this person a specific.php . I used below code but not
    worked:

    <?php

    if($_SERVER['HTTP_REFERER'] == "www.cominghost .com" ||
    $_SERVER['HTTP_REFERER'] == "cominghost.com " ||
    $_SERVER['HTTP_REFERER'] == "www2.cominghos t.com"){

    // Specific page html goes here

    }
    else
    {
    header("Locatio n: index.php");
    }
    ?>

    This code not worked for some cases like if the visitor comes from
    http://www.cominghost.com/account/targeturl.php or
    http://cominghost.com/account/targeturl.php Ok I know the if statement
    not working but How???

    Regards,
    Cem

  • ZeldorBlat

    #2
    Re: Sending people to specific pages that are coming from specific pages...

    First of all, don't count on the HTTP_REFERER (sic) variable to be
    accurate. It's up to the browser to set it, so it can always be
    incorrect or not there.

    Having said that, what you want is strpos():

    <http://www.php.net/strpos>

    Better yet, try his cousing stripos() for a case insensitive match. So
    something like this:

    if(stripos($_SE RVER['HTTP_REFERER'], 'cominghost.com ') !== false) {
    //Special code goes here
    }
    else {
    //Normal code goes here
    }

    Of course this isn't totally correct because
    http://www.foo.com/bar/cominghost.html would be accepted. If it's
    really that important, you can use a regular expression instead.

    Comment

    • Chung Leong

      #3
      Re: Sending people to specific pages that are coming from specific pages...

      See http://fi.php.net/parse-url/

      Comment

      Working...