Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Looking for Web Referral Script



8:00 pm on Mar 27, 2007 (gmt 0)

10+ Year Member

Hello everyone... This is what I am trying to do and I am hoping to find some examples or a program that already does this (I have been searching for a while and am at a loss at this point).

I want to allow other webmasters to send over traffic via a link somewhat like:


Then I would want to persist a cookie or some sort of tracking such that: If their surfer(referred user) ever comes back to these pages, THEIR affiliate link is retrieved from my database (based upon their SiteID and the settings they configured for that SiteID).

I would think that there would be something similar already out there, but I certainly can't find it if there is!

Thanks in advance :)

[edited by: dreamcatcher at 8:05 pm (utc) on Mar. 27, 2007]
[edit reason] Use example.com, thanks. [/edit]


8:21 pm on Mar 27, 2007 (gmt 0)

10+ Year Member

As long as you create a unique ID for each visitor that is available in the cookie they posess, you can use that ID to retrieve their "settings".

I guess the work has to be done by your database app -- you have to create the relatioship between the referal and the visitor -- you'll get the referral info only when the referral occurs, so make sure that you save it then -- if the user has to sign up, you can attach their profile (+settings) ID to the cooklie as well, but if your database does it already, the work is done.

Database design should be based on how you intend to use it (and the data it will contain) -- it will become incredibly difficult if you try to shoe-horn a generic/simple flat database design to a very specific and well defined and thought out click-process.

Consider and realize that a cookie is specific to a single browser installation on a single PC (ie: IE and FireFox on the same PC will submit/hold a different cookie) -- if you want to be able to track a visitor across all of their access means, you have to create a cookie and related database on your end that is smart enough to understand when you are visited by the same person (requiring logins help a bunch, but site-specific cookies can also do the job if they're well though out).


8:28 pm on Mar 27, 2007 (gmt 0)

10+ Year Member

Thanks for your response...

What I am hoping is that someone can give me a little 'direction' on how to create such a cookie such that it is persistent and works across as many platforms as possible.

I would have to assume that the same surfer will use the same browser otherwise I believe it might be difficult.

The database shouldn't be difficult to set up, but I will not be requiring the users to login - so I cannot track that way :(

Any more help is GREATLY appreciated :)


9:18 pm on Mar 27, 2007 (gmt 0)

5+ Year Member

I'm still learning PHP myself but I was wondering....
Will the cookies for each "surfer" be set on the affiliate's web site or your web site? If it is set on your affiliate's web site maybe you could set up a mySQL data base that contains a table for each affiliate. They might contain rows like the following:

AFFILIATE'S NAME: example inc.

ASSIGNED COOKIE ID: ( setCookie("referred_by_example_inc",$exampleinc,time() + 86400,"/"); ) - this particular example expires in 24 hours.

SURFER (I'm unsure whether these vistor's login or are random traffic. if random maybe capture their IP with something like "<? echo "$REMOTE_ADDR";?>" when they visit the page)

VISITS: (number of visits per IP within a set amount of time)

As I mentioned I'm very much a newbie at this but perhaps this will help get the wheels turning.

Good luck.


9:21 pm on Mar 27, 2007 (gmt 0)

5+ Year Member

Hey, check this out...
It might help...



9:41 pm on Mar 27, 2007 (gmt 0)

10+ Year Member

I was thinking more along these lines:

The site would send traffic to my site. At MY site, I would then store that user's information (cookie or otherwise) such that if they ever returned I would know who sent them...

My database would have:

SiteID: Referring Site ID for the webmaster's site
SitePW: Referring Site's password
Site_AffiliateLink: Referring Site's affiliate link

I would then read the cookie (or otherwise) to determine if this user was here before and is from a particular site. That cookie would likely be: User Identification + SiteID (of referring site).

After determining where the user came from, I would then display the correct affiliate link so that the originating website got proper credit for the referrald.

I read through that other article, but saw it was Perl and didn't go much furthur than that... I know php, so would prefer to keep it that way for now :)



10:53 pm on Mar 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

What I am hoping is that someone can give me a little 'direction' on how to create such a cookie such that it is persistent and works across as many platforms as possible.

Not sure what you mean by 'direction' for creating the cookie.

The setcookie() function will work just fine to create the cookie as long as it is on your domain. Set a cookie that has an id in it and just look for it every time a user comes back. The cookie is set on the users machine so it'll work for nearly everyone.



11:09 pm on Mar 27, 2007 (gmt 0)

5+ Year Member

Your plan sounds good although it reliyes on the ideal that the set cookie will remain on the users computer until they return again. Is there an incentive that would prompt the user to identify who the referrer was if the cookie were not present ( say, do to deleting the cookies on their computer)...Well I guess that's the affiliate's problem...as long as they come back to your site. I was trying to mess around with a solution that would set the cookie via a link but I couldn't get it to work.

<a href="http://example.com?&set_cookie=affiliateID=example_affiliate;path=/;Bdomain=.www.example.com;expires=DSat,+20+Feb+2008+01:31:52+GMT">set a cookie by clicking here!</a>

If you were interested in distributing custom buttons for your affiliates this might work if you posted it to php to put the results in your data base

<form action="http://www.example.com" method="post"
name="exampleform" id="exampleform">
<input type="hidden" name="affiliate_x" value="+1">
<a href="#" onClick="document.exampleform.submit();">Right This Way!</a>


Featured Threads

Hot Threads This Week

Hot Threads This Month