Show text based on which url the user came from

5 replies
I've been searching for this, but I can't figure out what to search for.

I'd like to have some php code to dynamically display some html to someone if they come from, say, twitter.

Anyone know how to do that or if there is a good source of this info somewhere?

Thanks very much,
#based #dynamic #html #php #show #text #twitter #url #user
  • Profile picture of the author unnatural
    Here's some example code to get you started. You just need to check the referring site, then do something based on that information ..

    $referrer = $_SERVER['HTTP_REFERER'];

    if (stristr($referrer,"twitter") != FALSE)) {

    echo "You came from twitter!";


    That's a basic example, and there's lots of ways to check the referrer and control the output, but that should get you started. If you need any more help just let me know.
    {{ DiscussionBoard.errors[4628200].message }}
    • Profile picture of the author philraymond
      Thanks so much for that. I ended up using the following. Just changed the " to ' and twitter to

      $referrer = $_SERVER['HTTP_REFERER'];

      if (stristr($referrer,'') != FALSE)) {

      echo 'yada yada';

      {{ DiscussionBoard.errors[4639451].message }}
  • Profile picture of the author unnatural
    Glad I could help
    {{ DiscussionBoard.errors[4639581].message }}
    • Profile picture of the author IvanJaquez
      Hello guys. I'm using wordpress and need to do something similar. How can I show text based on current url. For example: How to show a message base n this url struture: When a site visitor is checking any post n this subdomain how can I show an specific message for them. Any help?
      {{ DiscussionBoard.errors[5967511].message }}
  • Profile picture of the author xrampage16
    If you are using Drupal, you can check what the current url is by checking out the contents of $_GET['q']

    If you are using another content management system, you can probably do something similar by checking out the contents of $_GET, and seeing if the url is stored inside of there, or getting the contents of $_SERVER as "unnatural" suggests.

    Developer and Admin for Komputer King LLC hosting - Offering lightning fast web hosting and Quality Backlink Building

    {{ DiscussionBoard.errors[5967800].message }}

Trending Topics