PHP Question for PHP Pro

by 9 replies
11
If I use an include function on my index page, which says something like "if user came from ESPN include Sports.php page, else include Music.php page" so the user will stay on the index.php page but what he is shown will be different based on where he came from, is this something that user can identify?
#programming #php #pro #question
  • Only way I know how to do that is by using 'HTTP Referer'. Unfortunately it's not 100% reliable, because not all browsers support it. But it should work for the majority of your visitors.


    <?php

    $referer = $_SERVER['HTTP_REFERER']; // Get the referring URL and put it in a variable

    if(isset($referer)) // Check to make sure that the variable is set
    {
    $espn = strpos($referer, "espn"); // Search the variable to see if it contains "espn"
    if ($espn === true) {
    include ('Sports.php'); // If it does, include Sports.php
    } else {
    include ('Music.php'); // If it doesn't, include Music.php
    }
    }

    ?>
    • [1] reply
    • Actually that's not quite true. All major browsers, including all the mobile browsers, support the HTTP Referer header (yes, the misspelling of referrer is accurate..). The problem is, and why it's not 100% reliable, is that plugins, or even the browser's settings, can allow users to either spoof or turn off the sending of this header. Since it's totally up to the client (browser), whether or not to send it, you can't always count on it. You can, however, count on it to be there for 99% of users, if not more, so it can tell you something. You just need to account for cases where it isn't being sent to the server.
      • [1] reply
  • Usually we use this to fool SE spiders. It's called "Cloaking". Check the wikipedia article.
    • [1] reply
    • @Brandon Tanner,
      Can you please advise me, what development environment do you recommend for testing such things on my Windows PC before potentially screwing up an active WordPress blog?
      • [1] reply
  • If you design your site in wordpress then you can do that by adding some plugins.
    If you are not using wordprees then you have to that by coding php program.
  • Thanks, Brandon, I will take a look at InstantWP.

Next Topics on Trending Feed

  • 11

    If I use an include function on my index page, which says something like "if user came from ESPN include Sports.php page, else include Music.php page" so the user will stay on the index.php page but what he is shown will be different based on where he came from, is this something that user can identify?