Jump to content


This topic is now archived and is closed to further replies.


Add session variable for 3rd party referrer?

Recommended Posts

Sorry, I've done a lot of searching but can't tell if this is standard fare that I don't quite understand, or if it's something not very common or easy to do with OSC.


We're setting up our site to receive hits from various referrers, and it needs a session variable to track where the click came from, and that that user followed their visit through to a purchase. So the string coming from the referrer (say "Some Company" with ID # ABC123) is something like ?referrerName=SomeCompany&refID=ABC123... i.e.




How do I add this URL string or set a session variable, so EVERY page the whole time I'm browsing retains that string? i.e.




From what I've gathered it sounds like it's something in application_top.php, but I just can't quite figure out what. Hopefully it's simple and straightforward, common practice for someone else! :) Any help on this would be great. Thanks!

Share this post

Link to post
Share on other sites

One way:


In /catalog/includes/application_top.php before this code:


// set SID once, even if empty
 $SID = (defined('SID') ? SID : '');


Add this code (modify it to include your referrer names and ID's):


  $link_refs = array(
"Acme" => "a1b2c3",
"Nutz-R-Us" => "f9c4l5",
"Edsel"  => "h9k73b",
"WhoozWho" => "q9z5g4",
"PartsIzParts"  => "u2m3r1");

 if ( $referrerName = $_GET['referrerName'] ) {
   if ( $refID = $_GET['refID'] ) {
     if ( $link_refs[$referrerName] != "" ) {
       if ( ! tep_session_is_registered('referrerName') ) {
         $refID = $link_refs[$referrerName];


That part identifies and registers the referrer names and ID's.


To include them in the links this code in /catalog/includes/functions/html_output.php


// The HTML href link wrapper function
 function tep_href_link($page = '', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true) {
   global $request_type, $session_started, $SID;


Change the last line in that code to this:


    global $request_type, $session_started, $SID,$referrerName,$refID;


Then in that same function BEFORE this code:


    if (isset($_sid)) {
     $link .= $separator . tep_output_string($_sid);


Add this code:


    if ( tep_session_is_registered('referrerName') ) {
     $link .= $separator . "referrerName=" . tep_output_string($referrerName);
     $separator = '&';

   if ( tep_session_is_registered('refID') ) {
     $link .= $separator . "refID=" . tep_output_string($refID);


This worked in a test area I have.



If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.


"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -


"Headers already sent" - The definitive help


"Cannot redeclare ..." - How to find/fix it


SSL Implementation Help


Like this post? "Like" it again over there >

Share this post

Link to post
Share on other sites