View Single Post
Old 07-20-2011, 01:52 AM  
robber
Web Developer
 
Industry Role:
Join Date: Jan 2011
Location: UK
Posts: 264
Hi Guys,

I've just looked back over what I wrote and I need to amend the header scripts just slightly. But I have also expanded on a few points raised above as well regarding processing and how to do this in a separate file

##################################################

If you are storing your affiliate ID in a session, your header script should be:

Code:
<?php session_start(); #<-- Must be first line
if(!empty($_POST['id'])){$_SESSION['affid'] = $_POST['id']; #<-- Sets the affiliate id
$affid = $_SESSION['affid'];} #<-- assign affiliate id
if(empty($_SESSION['affid'])){$affid = "xxxxxx";} #<-- add a default value
 ?>
If you are storing your affiliate ID in a cookie your header script should be:
Code:
<?php 
if(!empty($_POST['id'])){setcookie("affid",$_POST['id']); #<-- Sets the affiliate id
$affid = $_COOKIE['affid'];} #<-- assign affiliate id
if(empty($_COOKIE['affid'])){$affid = "xxxxxx";} #<-- add a default value
 ?>
The rest should stay the same, so where you want to have your input box to insert your affiliate id put in:

Code:
<form action="<?php 
echo $_SERVER['PHP_SELF']; # This will loop round to the same page, if you have a specific page you would like to direct to, just replace this whole php tag with the url/link to the page eg. "afflink.php"
 ?>" method="post">
<input type="text" name="id" value="<?php echo $affid; ?>">
</form>
If you want to process your link in an individual file your individual file should look like (You still need to have the header script in place to enable this to work):

### If Using Sessions ###
Code:
<?php
session_start(); #<-- Must be first line
if(!empty($_POST['id'])){$_SESSION['affid'] = $_POST['id']; #<-- Sets the affiliate id
header("location: #File name here#"); #put in the file name eg. index.php
exit(); #This will stop the script processing any further
?>
### If Using Cookies ###
Code:
<?php
if(!empty($_POST['id'])){setcookie("affid",$_POST['id']); #<-- Sets the affiliate id
header("location: #File name here#"); #put in the file name eg. index.php
exit(); #This will stop the script processing any further
?>
If you wanted to have a different file (one which is showing content) to be the page the user goes to after inserting their code, then just put the link in the form tags (as described above) and make sure that file has the header script in it and everything will work automatically.

Then wherever you would like to insert the affiliate code put:
Code:
<?php echo $affid; ?>
I hope this works for you, and it has covered most amendments and basic additional options for how you process the affiliate code on your site.

If you are storing your affiliate ID in a database, please contact me and I will help you write the code as every database is different in design and naming and so I wouldn't be able to cover that in this tutorial. Please send help requests to: [email protected] (please replace the 0's for o's)

Rob

Last edited by robber; 07-20-2011 at 01:58 AM.. Reason: Just a few amendments, and ironing out what I meant
robber is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook