Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    126
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Capturing where user has came from?

    One of my clients wants applications sent to different email addresses based on where the user has came from.
    I know i can use the referrer php code but when the user clicks the apply button the referrer changes to the home page url. if that make sense?

    So what i have done is add this to the homepage:


    <?php
    $referrer = $_SERVER['HTTP_REFERER'];
    ?>

    I need to pass the $referrer var to the contact page, and then it also needs to go into the sendmail.php script.

    So i would use something like

    <?php
    if $referrer == "yahoo adwords link, whatever that may be?" {
    $address = "firstaddress";
    } elseif $referrer == "google adwords link, whatever that may be?" {
    $address = "secondaddress";
    }
    ?>

    Basically my client wants to know where leads are coming from, if they come from yahoo he wants it to go to his yahoo address. If it comes from google adwords he wants it to go to his gmail address.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,525
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    How about using Google Analytics?
    That would go right along with Adsense.

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Posts
    126
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mlseim View Post
    How about using Google Analytics?
    That would go right along with Adsense.
    we already use that but i think he wants to go down the separate email route

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    If the HTTP_REFERER (yes its spelled wrong in PHP) is given to you, you can determine its base url with the parse_url function. This in combination with an in_array will give you what you need.
    PHP Code:
    $ref $_SERVER['HTTP_REFERER'];
    $addr 'somedefaultaddress';
    if (!empty(
    $ref))
    {
        
    $host parse_url($refPHP_URL_HOST);
        if (
    in_array($host'yahoo.com'))
        {
            
    $addr 'yahooaddress';
        }

    And so forth. parse_url returns an array by default that parses each little thing, but will not separate the querystring. This example only captures the host part (which I'm fairly certain includes the suffix). Use an in_array or a switch to use the correct address.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    Regular Coder
    Join Date
    Jun 2007
    Posts
    126
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thanks thats great. How can i push the REFERER to the apply page.

    google > site index page > apply page

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    To persist? Use a session for that, which actually works very nicely:
    PHP Code:
    <?php
    session_start
    ();
    if (!isset(
    $_SESSION['ref']) && !empty($_SERVER['HTTP_REFERER']))
    {
        
    $ref htmlspecialchars($_SERVER['HTTP_REFERER']);
        
    $ref urlencode($ref);
        
    $_SESSION['ref'] = $ref;
    }
    Then when you need to use the referrer check, extract from $_SESSION['ref'] instead of $_SERVER['HTTP_REFERER']. May need to play around with the changes on the htmlspecialchars / urlencode there. Sadly, referrer is tainted data.
    Oh, you'll need session_start called prior to any use of the $_SESSION, so add that to the top of the apply page before doing the checks.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #7
    Regular Coder
    Join Date
    Jun 2007
    Posts
    126
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I've made it work but the session is keeping old values even when i re access the site

    for example clicking from google gives google.com ref then i'll go to yahoo and it will give google.com still. i can use session_destroy() which works but it then kills everything so cant push it to next page

    any ideas?

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    When they reach the assigned page:

    Code:
    if (isset($_SESSION['ref']))
    {
        unset($_SESSION['ref']);
    }

  • #9
    Regular Coder
    Join Date
    Jun 2007
    Posts
    126
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks MattF that worked.

    When i click submit on the form its giving this error:

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/username/public_html/join.php on line 61

  • #10
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Assuming that's the in_array line Fou-Lu posted?

    Code:
        $host = parse_url($ref, PHP_URL_HOST);
        if (stripos($host, 'yahoo.com') !== false)

  • #11
    Regular Coder
    Join Date
    Jun 2007
    Posts
    126
    Thanks
    4
    Thanked 0 Times in 0 Posts
    its working many thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •