Web Analytics Made Easy -
StatCounter Redirect popup based on referrer or host IP address - CodingForum


No announcement yet.

Redirect popup based on referrer or host IP address

  • Filter
  • Time
  • Show
Clear All
new posts

  • Redirect popup based on referrer or host IP address

    Hi, I want to use something like the "document.referrer" property and also the visitor's IP address to pop up a selection of pages depending on where the visitor links from. I've found lots of scripts that will pop up on a single referrer URL but nothing that will make a selection from a number of pages based on different referrers and source addresses. Alternatively, I could use this to load a different page into an iframe.

    Basically, I want to greet people linking in from selected websites or visiting from selected companies with info that's most relevant to them.

    I should add that if you give me a code snippet I may not know what to do with it but I will do my best!

    many thanks in advance


  • #2
    Based on your last sentence, it doesn't sound like you're a coder...

    I would suggest a switch statement or an if/else if/else if clause.

    Why don't you post your sample script that works on one http_referrer. That way we might get a better idea of what you're really talking about, and how to help you out.



    • #3
      Hi and thanks for your help - your guess is correct, I'm not really a coder.

      So far, I have got the multiple referrers working although it's a bit clumsy, using javascript, so I'm starting from scratch with PHP based on a recommendation from the JS forum.

      <SCRIPT LANGUAGE="JavaScript"><!--
      if (top.document.referrer == "http://www.ppimk.com/")
      else if (top.document.referrer == "http://www.trainerbase.co.uk/")

      For instance, I have to specify the exact referrer rather than being able to specify just the domain part, as some sites link from multiple pages.

      Secondly, I would like to include something to also recognise the visitor's IP address.

      And if that wasn't enough, I'm also trying to get a cookie set so the popup only loads once. The current workaround is that it loads in the frameset's navigation bar, so at least it only loads once per visit.

      If you can work through that lot then I am very, very grateful!



      • #4
        As far as grabbing the domain, check this out:

        As far as grabbing the user's IP address, check this out:

        The algorithm I would use is as follows:
        check the cookie
        if set, do nothing
         grab the domain or visitor's ip address
         do your if else clause to figure out what page to popup
         store the popup page as $popup_page;
         <script>window.open("<?php echo $popup_page; ?>",...);</script>
        Maybe someone will be kind enough to code that up for. Let me know if you have any problems with that.

        BTW. I don't really understand how you decide if you're going to use the referrer or the ip address, but you'll have to specify further there.

        Hope that helps,


        • #5
          Thankyou- I will check out those links. What I had in mind, structure-wise was:

          if referrer= then popup page 1

          else if referrer=then popup page 2

          else if IP address=then popup page 3

          But I don't know if referrer and host address are on the same level and can be compared in this way.

          thanks again