Results 1 to 6 of 6

Thread: referral script for contact form

  1. #1
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default referral script for contact form

    Hi

    need some help, thought I might start here.

    I have a simple contact form, i have 1 website with 3 unique domain names that I would like to track as referrals in form.

    ab.com = ppc link
    cd.com = email link.
    de.com = forum link

    How do I capture the link information as a hidden field in my basic form and not the domain name?

    Thanks

  2. #2
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    As you've posted this in the PHP forum i'll assume you know PHP.
    You could use a simple switch statement to change the variable $link depending on the refering page e.g.

    PHP Code:
    $referer $_SERVER['HTTP_REFERER'];
    switch (
    $referer)
        {
        case 
    "ab.com":
            
    $link "ppc link";
            break;
        case 
    "cd.com":
            
    $link "email link";
            break;
        case 
    "de.com":
            
    $link "forum link";
            break;
        } 
    Then for the hidden field:
    HTML Code:
    <input name="link" type="hidden" value="<?php print $link; ?>" />

  3. The Following User Says Thank You to jc_gmk For This Useful Post:

    dhype55 (03-27-2008)

  4. #3
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Exactly what I was looking for, not very good with PHP, but i'll try to make it work.

  5. #4
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I'm using this as my finished script, I hacked some code together to parse the http_referrer

    <?php

    $ref = $HTTP_SERVER_VARS["HTTP_REFERER"];

    if (empty($ref)) {

    $remote_host = "Direct Request";

    }
    else
    {

    $come_from = parse_url($ref);
    $remote_host = str_replace("www.","",$come_from[host]);
    switch ($remote_host)
    {
    case "ab.com":
    $link = "ppc link";
    break;
    case "cd.com":
    $link = "email link";
    break;
    case "de.com":
    $link = "forum link";
    break;
    }

    }


    ?>


    Is that right? It works, but i'm not sure if that's the best way to cobble the code together.

    thanks

  6. #5
    Join Date
    May 2007
    Location
    England, UK
    Posts
    235
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default

    Maybe try this:

    PHP Code:
    $ref str_replace("http://","",$HTTP_SERVER_VARS["HTTP_REFERER"]);
    $ref str_replace("www.","",$ref);
    $ref explode("/",$ref);
    $ref $ref[0];

    switch (
    $ref
        { 
        case 
    "ab.com"
        
    $link "ppc link"
        break; 
        case 
    "cd.com"
        
    $link "email link"
        break; 
        case 
    "de.com"
        
    $link "forum link"
        break; 
        default:
        
    $link "Direct Request"
        break;
        } 
    It will remove the http:// and www. and if the referer is something like http://ab.com/index.php?p=something it will remove everything after the /

    Also I have removed the if statement because it does the same thing as switch, only i've put a default in there which is the same as an else

  7. The Following User Says Thank You to jc_gmk For This Useful Post:

    dhype55 (03-27-2008)

  8. #6
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    This could come in handy However if I may ask;

    Scenario:
    I have a website that has a link to another site (different domain) but I want to track the referring domain. There is a form the user may submit on the new domain site, now what I want to do is add a referrer code/value of the domain that the person was referred from.

    Now the issue is that the person may visit a number of pages of the second site so the above will thus show the referrer as the last page visited - but how do I get it to show the referrer as being the other domain?

    Thanks

Bookmarks

Posting Permissions

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