SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP HTTP Referrer Session Telehone Number Changing

    Hi I have been trying to show different telephone numbers per referrer through out all site pages, the script i have hashed together is below, it works and checks referrer then displays the correct number, how ever upon clicking internal links within my site the new referrer is then my site so it then shows the default.

    There must be away to store and use the original referrer, then show a message across all site pages quoting the referrer relevant number.

    Many thanks to anyone that can help

    <?PHP
    session_start();
    if (isset($_SESSION['referrer'])) {
    $referrer = $_SESSION['referrer'];
    } else {
    $referrer = strtolower($_SERVER["HTTP_REFERER"]);
    }
    if (strstr($referer,"essential"))
    {
    echo("<h1>Telephone Number1</h1>");
    }
    else if (strstr($referer,"site2"))
    {
    echo("<h1>Telephone Number2</h1>");
    }
    else if (strstr($referer,"site3"))
    {
    echo("<h1>Telephone Number3</h1>");
    }
    else if (strstr($referer,"site4"))
    {
    echo("<h1>Telephone Number4</h1>");
    }
    else
    {
    echo("<h1>Telephone Number5</h1>");
    } $_SESSION[’referrer’] = $referrer; // store session data
    ?>

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do you really have ’angled single quotes’ in that last line of code or is that some artifact from copy/pasting?

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Can you simply store the telephone number in the session instead of having to do this lookup? That way you just do it once per site visit.

    Example, not tested.
    PHP Code:

    $referer 
    'site1' // don't know where this is coming from?

    // maintain a central array of phone numbers in an array
    $tels = array(
     
    'site1' => '12345'
    ,'site2' => '45678'
    );

    if( 
    array_key_exists$referer $tels ) ) {
           
    $_SESSION['tel'] = $tel[$referer] ;
    }else {
           
    $_SESSION['tel'] = '98765' // hard-code default tel


  4. #4
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No that must be from copying and pasting.

    The telephone number array and selection is fine for the initial page of the site but after a click through to another page it shall loose the original referrer number and change to mysite referrer number.

    Any more help appreciated.

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What do you do for all the people who turn off that field so that sites can't breach their privacy by telling what page they were on last?

    Your best solution is to establish a session when people visit your site and pass a unique identifier between pages using the session so as to track what number to show. You can't really tell for sure where they came from before getting to your site but you could use the referrer when it does have something in it to choose which number to load into the session.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •