Simple Machines Community Forum

SMF Support => SMF 1.1.x Support => Aiheen aloitti: VanGogh - maaliskuu 17, 2005, 10:31:56 AP

Otsikko: Tracking referrers with SSI.php?
Kirjoitti: VanGogh - maaliskuu 17, 2005, 10:31:56 AP
Hey,

So, I'm looking for a way to track who was referred in by whom.  In other words, if I have a current member of the forum who tells his buddy about my site, and his buddy signs up to the forums, is their any way that I can track\display that my member has one referral?

The reason I ask is because I'm looking at running contests in which the members of my board have a chance at winning prizes based upon how many new members they have referred in over the past month.

My entire site is in php, and every page uses the SSI.php. What I would like to do is add a bit of code to SSI.php that sets a variable based on the url. So if my member Waldo wants to refer people to my site, he'd just give them this url: http://www.mysite.com/index.php?referrer=Waldo . I want to be able to pass the referrer variable from page to page in case the new person wants to look around a little before they sign up.

So, three questions:

Is it possible to alter the SSI.php file to grab the referrer variable and add it to a session, so I can then use it in a custom field during registration?

If so, how would I do that?

And will this work even if the new person visits the forum first? (I.E. Does SSI.php get used in the forum itself, or would I have to edit other files to get it to work in there?)

Many thanks to anyone who can give me a little help or insight,
VanGogh

P.S. If you have a better idea on how to do this, I'd love to hear that too!
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: VanGogh - maaliskuu 21, 2005, 08:51:31 IP
*Bump*  I could REALLY use a little help with this...

In SSI.php I found this:

// Start the session... known to scramble SSI includes in cases...
if (!headers_sent())
loadSession();
else
{
if (!isset($_SESSION['rand_code']))
$_SESSION['rand_code'] = '';
$sc = &$_SESSION['rand_code'];

// Note that PHP 4.2.x and above, only, auto-seed.
if (@version_compare(PHP_VERSION, '4.2.0') == -1)
srand(time());
}


Immediately after that, I've added this:


//My EDIT
if ($_GET['gfad']!='') {
$_SESSION['gfad'] = $_GET['gfad'];
}


So theoretically, if a user enters my url as http://www.mysite.com/index.php?gfad=BUBBA then it should grab and store BUBBA.  The problem is that it keeps spitting out an unkown index error for that cooresponds with line where I added my code. Any idea on what I might be doing wrong?
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: Oldiesmann - maaliskuu 22, 2005, 11:14:18 AP
Try this:

if(isset($_GET['gfad']))
{
    $_SESSION['gfad'] = $_GET['gfad'];
}
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: VanGogh - maaliskuu 22, 2005, 11:41:45 IP
EXCELLENT!

That works like a charm!

Now, last question and I should have this thing in shape:

How do I pass that variable onto the registration form? I've created a custom field, and basically I'd like to harvest the variable and put it in there. I'm using this code, but it's not working.


</tr><tr>
<td width="40%">
<b>Referred By:</b>
</td>
<td>
<input type="text" name="text_gfad" size="20" maxlength="18" VALUE="$gfad" />
</td>


I'm assuming that all variables in the session are passed on to the forum itself, and thus can be accessed from any page inside of it.  Am I wrong?
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: [Unknown] - maaliskuu 22, 2005, 11:43:47 IP
Don't abuse globals.  If you want a session variable, use $_SESSION['gfad'].  If you want a request variable, use $_REQUEST['gfad']... etc..

-[Unknown]
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: VanGogh - maaliskuu 22, 2005, 11:48:56 IP
Ok...

Please keep in mind that I'm a PHP idiot. So I tried this:


</tr><tr>
<td width="40%">
<b>Referred By:</b>
</td>
<td>
<input type="text" name="text_gfad" size="20" maxlength="18" VALUE="$_SESSION['gfad']" />
</td>


It results in the Template Parse error screen.

What am I missing?
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: [Unknown] - maaliskuu 22, 2005, 11:55:41 IP

</tr><tr>
<td width="40%">
<b>Referred By:</b>
</td>
<td>
<input type="text" name="options[text_gfad]" size="20" maxlength="18" value="', $_SESSION['gfad'], '" />
</td>


That may be what you're looking for...

-[Unknown]
Otsikko: Re: Tracking referrers with SSI.php?
Kirjoitti: VanGogh - maaliskuu 23, 2005, 12:00:20 AP
YES!

That works great.  I cannot say thank you enough to both of you for the help.  I've been trying to puzzle out this refferal system for a few weeks now.  Awesome support on a great forum system!