SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP session tracking - help required

    I'm totally new to PHP, so forgive my ignorance, but could anyone tell me where I'm going wrong here?

    I'm trying to track visitors to our website who have been referred from other sites. I then want to pass on the affiliate's details when they leave the site.

    The following script is at the top of the home page:

    PHP Code:
    <?php session_start(); $_SESSION["affiliatecode"] = htmlentities(trim(@$_REQUEST["affiliatecode"])); ?>
    <?php session_start
    (); $_SESSION["campaignID"] = htmlentities(trim(@$_REQUEST["campaignID"])); ?>
    <?php session_start
    (); $_SESSION["sourceBusID"] = htmlentities(trim(@$_REQUEST["sourceBusID"])); ?>
    <?php session_start
    (); $_SESSION["activityID"] = htmlentities(trim(@$_REQUEST["activityID"])); ?>
    Then at the end of the link to leave the site I've got:

    PHP Code:
    &affiliatecode=<?php echo @$_SESSION["affiliatecode"]."&campaignID".@$_SESSION["campaignID"]."&sourceID".@$_SESSION["sourceID"]."&activityID".@$_SESSION["activityID"];?>
    The idea being that the variables "affilatecode", "campaignID", "sourceID" and "activityID" are passed to the external site.

    At the moment, it just passes the affiliatecode and skips the rest.

    Any ideas?

    Thanks in advance

  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)
    1) You only need to call session_start() once on the page, not before every access to $_SESSION

    2) You are missing the = between the keys and values after every key except affiliatecode

    You want "&campaignID=123", not "&campaignID123"

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,491
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Don't use @
    Try this code:
    PHP Code:
    <?php 
      session_start
    (); 
      
    $_SESSION['affiliatecode'] = htmlentities(trim($_REQUEST['affiliatecode']));
      
    $_SESSION['campaignID'] = htmlentities(trim($_REQUEST['campaignID'])); 
      
    $_SESSION['sourceBusID'] = htmlentities(trim($_REQUEST['sourceBusID']));
      
    $_SESSION['activityID'] = htmlentities(trim($_REQUEST['activityID']));
    ?>

  4. #4
    SitePoint Member
    Join Date
    May 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So would this be correct for the top of the page?

    <?php session_start(); $_SESSION["affiliatecode"] = htmlentities(trim(@$_REQUEST["affiliatecode"]));
    $_SESSION["campaignID"] = htmlentities(trim(@$_REQUEST["campaignID"]));
    $_SESSION["sourceBusID"] = htmlentities(trim(@$_REQUEST["sourceBusID"]));
    $_SESSION["activityID"] = htmlentities(trim(@$_REQUEST["activityID"])); ?>

  5. #5
    SitePoint Member
    Join Date
    May 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Dan and guido, think I posted at the same time, but I'll try your code now.

  6. #6
    SitePoint Member
    Join Date
    May 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, this is the code I'm using now, but it's still only passing the first variable:

    PHP Code:
    <?php 
      session_start
    (); 
      
    $_SESSION["affiliatecode"] = htmlentities(trim(@$_REQUEST["affiliatecode"]));
      
    $_SESSION["campaignID"] = htmlentities(trim(@$_REQUEST["campaignID"])); 
      
    $_SESSION["sourceBusID"] = htmlentities(trim(@$_REQUEST["sourceBusID"]));
      
    $_SESSION["activityID"] = htmlentities(trim(@$_REQUEST["activityID"]));
    ?>
    and then this code on the end of the link:

    PHP Code:
    &affiliatecode=<?php echo @$_SESSION["affiliatecode"]."&ampcampaignID=".@$_SESSION["campaignID"]."&ampsourceBusID=".@$_SESSION["sourceBusID"]."&activityID=".@$_SESSION["activityID"];?>
    I tried removing the @s from this, but it made no difference.
    Last edited by hrwebpro; May 6, 2009 at 01:04. Reason: error in code


Tags for this Thread

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
  •