Jump to content


Photo
* * * * * 1 votes

[PHP] - [Affiliation Script] - [Gio]


  • Please log in to reply
17 replies to this topic

#1 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 27 September 2004 - 11:36 AM

Ok I will break this into parts so it will not be so confusing.

First were going to make the sql table.

SQL
CREATE TABLE affiliates (
id int(11) NOT NULL auto_increment,
countout smallint(3) NOT NULL,
countin smallint(3) NOT NULL,
wb_name varchar(20) NOT NULL default '',
wb_email varchar(30) NOT NULL default '',
ws_name varchar(20) NOT NULL default '',
ws_desc varchar(20) NOT NULL default '',
ws_link varchar(75) NOT NULL default '',
ws_button varchar(75) NOT NULL default '',
PRIMARY KEY (id),
KEY id (id)
) TYPE=MyISAM;

All this is, is the information for the site you are linking. WB stands for Web Master. WS stands for web site DUH!!!1 and the id like always is unique like a snow flake there shall be no 2 the same. The countin and countout are the hits generated in and out from that specific site.

Now for the counting of the hits in and out, were going to call this counter.php

Counter.php
<?
// We need to connect to the sql db
include "connect.php";

// Affiliates linking to you should do so like this: http://yoursite.com/counter.php?inid=1
// So it will count the hits coming from the affiliate website with the ID = 1!
if (isset($inid)){

// This will count for that website!
$update = mysql_query("UPDATE affiliates SET countin = countin + 1 WHERE id='$inid'");

// After that redirects to your website.
$url = "http://yoursite.com";

header("Location: $url");

mysql_close();
}

// The variable $outid you´ll use to link to your affiliates.
// This variable will be in the url on the affiliates´ buttons in your site!
if (isset($outid)){

// Count it
$update = mysql_query("UPDATE affiliates SET countout = countout + 1 WHERE id='$outid'");

// Select the website url with the given ID
$result = mysql_query("SELECT ws_link FROM affiliates WHERE id='$outid'");

$row = mysql_fetch_array($result);

$url = $row['ws_link'];

// And redirect to it
header("Location: $url");

mysql_close();
}
?>

Pretty much the commenting does it all, for people linking to you, they use the counter.php?inid=# of the affiliate linking to you. And when someone clicks the link off there site it updates it on your site. Also for linking on your site it is the same concept, counter.php?outid=# to affiliate you are linking to.

And now but not least, affiliates.php!

Affiliates.php
<?
include "connect.php";

$result = mysql_query("SELECT * FROM affiliates ORDER BY id");
while($row = mysql_fetch_array($result)){

echo "<p><a href=\"http://yoursite.com/counter.php?outid=".$row['id']."\" target=\"_blank\"> 
<img src=\"".$row['ws_button']."\" width=88 height=31 alt=\"".$row['ws_name']."\" border=\"0\"></a><br>in: " . $row['countin'] . " | out: " . $row['countout'] . "</p>"; 
}
?>

To randomize the displaying of the affiliates update affiliates.php to this code.

Affiliates.php
<?
include "connect.php";

$result = mysql_query(" SELECT * FROM affilliates ORDER by RAND();");
while($row = mysql_fetch_array($result)){

echo "<p><a href=\"http://yoursite.com/counter.php?outid=" . $row['id'] . "\" target=\"_blank\"> 
<img src=\"" . $row['ws_button'] . "\" width=88 height=31 alt=\"".  $row['ws_name'] ."\" border=\"0\"></a><br>in: " . $row['countin'] . " | out: " . $row['countout'] . "</p>"; 
}
?>

Now to only display a select number of random affiliates use this code.

display.php
<?
include "connect.php";

$result = mysql_query("SELECT * FROM affilliates ORDER by RAND() LIMIT 0,3");
while($row = mysql_fetch_array($result)){

echo "<p><a href=\"http://yoursite.com/counter.php?outid=" . $row['id'] . "\" target=\"_blank\"> 
<img src=\"" . $row['ws_button'] . "\" width=88 height=31 alt=\"".  $row['ws_name'] ."\" border=\"0\"></a><br>in: " . $row['countin'] . " | out: " . $row['countout'] . "</p>"; 
}
?>


#2 Jamie Huskisson

Jamie Huskisson

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 3,648 posts
  • Gender:Male
  • Location:Nottingham, UK

Posted 27 September 2004 - 11:51 AM

fixed

#3 sully

sully

    Young Padawan

  • Members
  • Pip
  • 22 posts

Posted 22 October 2004 - 03:39 AM

Nice tutorial :) Bit to basic for me - the managment of affiliates and stuff. But its a good one all the same :)

- Sully :D

#4 AND1Games

AND1Games

    Young Padawan

  • Members
  • Pip
  • 1 posts

Posted 08 March 2005 - 03:36 PM

i had this error:

error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\WM\www\affiliates\affiliates.php on line 5


#5 edskii

edskii

    Young Padawan

  • Members
  • Pip
  • 49 posts

Posted 15 April 2005 - 03:53 PM

How would you put that Random Affiliate script into verticle marquee scrolling?

Help appreciated :)

#6 Decrypt

Decrypt

    Young Padawan

  • Members
  • Pip
  • 4 posts

Posted 01 May 2005 - 01:57 PM

Nice Tutorial!

#7 syphon

syphon

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 19 August 2005 - 07:07 AM

How would you put that Random Affiliate script into verticle marquee scrolling?

Help appreciated ;)

use the second to last display script and format the information using HTML/CSS into one icon per line. Scroll that and you should have a random affiliate marquee.

PM me, or anyone else if you need help ;)

du

Edited by syphon, 19 August 2005 - 07:07 AM.


#8 finlay

finlay

    Young Padawan

  • Members
  • Pip
  • 45 posts
  • Interests:Adobe, PHP

Posted 20 September 2005 - 01:07 PM

Good tutorial, i made something even more basic than that for my site.

#9 albinoAZN

albinoAZN

    Albinos Are Extinct!!!

  • Members
  • PipPipPipPip
  • 1,139 posts
  • Gender:Male
  • Location:Mississippi, USA

Posted 18 November 2005 - 09:48 AM

i'm not too sure on how you actually add affiliates. Your help is appreciated. Also, i noticed that you never tell us to make a connect.php document, and what to put in it.

Ok, i made a connect.php page, and put this in it.
<?php

$l = mysql_connect ( "localhost" , "yourmysqlUser" , "password" ) or die("Error connecting: <br><br>".mysql_error());
mysql_select_db( "yourdatabase" ) or die("Error getting db: <br><br>".mysql_error());

?>

Changing the required information of course. Now whenever i go to display.php, i get the following SQL Error.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/albino/public_html/display.php on line 5
Thank you.


Albino

Edited by Albino4zn, 18 November 2005 - 10:16 AM.


#10 ComputerGeekXD

ComputerGeekXD

    Young Padawan

  • Members
  • Pip
  • 27 posts

Posted 20 November 2005 - 09:33 PM

Dude...This is like a partial tutorial. ;) You didn't tell us how to add or delete affiliates, or about connect.php. Please, I would like to use this!!

#11 Donna

Donna

    Retired P2L Queen!

  • P2L Staff
  • PipPipPipPip
  • 12,330 posts
  • Gender:Female
  • Location:B.C Canada

Posted 20 November 2005 - 09:37 PM

Gio hasn't been around on P2L since March so you'd be better off asking your questions via PHP Help Forum, you'll get a quicker response.

http://www.pixel2lif...hp?showforum=10

#12 ComputerGeekXD

ComputerGeekXD

    Young Padawan

  • Members
  • Pip
  • 27 posts

Posted 22 November 2005 - 01:58 AM

Ah...Okay, thanks Donna.

#13 Gio

Gio

    Jedi In Training

  • Members
  • PipPip
  • 317 posts

Posted 12 December 2005 - 04:59 PM

Sorry guys I was planning on making a part 2 but alot of stuff came up and well my personal life as is, is a tad bit hectic but I will see what I can do.

#14 fedekiller

fedekiller

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 25 April 2006 - 02:40 PM

i was lazy to program an affi system from 0, so i used part of this one
:mellow: with admin cp, you need to have a user system
i added another field to the table, called state
char, 2
config file contain:
- sql information
- your website
for example
$website = 'http://mysite.com';
mysql_connect("localhhost....blablabla

affiliates_admin.php

<?php
session_start();
if($_SESSION['loggedin']){?>
<?php
include("config.php");
echo "Affiliation Requests:<br><br>";
$result = mysql_query("SELECT * FROM affiliates WHERE state='0' ORDER BY id DESC");
while($r = mysql_fetch_array($result)){
echo "Webmaster Name: $r[wb_name]<br>
Webmaster Email: $r[wb_email]<br>
Website Name: $r[ws_name]<br>
Website Desciption: $r[ws_desc]<br>
Website Link: $r[ws_link]<br>
Website Button: $r[ws_button]<br>
This is the link that the webmaster has to add in his/her site to link this one:<br>
$website/count.php?inid=$r[id]<br>
<a href=affiliates_admin.php?accept&aid=$r[id]&em=$r[wb_email]>accept?</a> | <a href=affiliates_admin.php?delete&did=$r[id]>delete?</a>";
}

if(isset($_GET['accept'])){
$id = $_GET['aid'];
$email = $_GET['em'];
$ok = mysql_query("UPDATE `affiliates` SET `state`= '1' WHERE `id` =$id LIMIT 1;");
if($ok){
echo "The affiliate has been accepted.";
$message = "
Your affiliation with $web_name has been accepted, congratulation! ^-^, add this code in your website to link this one $website/?fd=affiliates&nav=count&inid=$id and you can use this button $af_btn
";
mail("$em","Affiliation Accepted","$message");
}else{
echo "Oops, Error.";
};
}else if(isset($_GET['delete'])){
$id = $_GET['did'];
$ok = mysql_query("DELETE FROM `affiliates` WHERE id='$id' LIMIT 1");
if($ok){
echo "The request has been deleted.";
}else{
echo "Oops, Error.";
};
}
?>
<?php
}else{
echo "Wowowowowowo, you are not logged in...";
};
?>


apply for affiliation

apply.php

<form action="apply.php" method="post"><table border="0">
<tr>
<td>Owner Name </td>
<td><input name="oname" type="text" id="oname" size="20" maxlength="20"></td>
</tr>
<tr>
<td>Owner Email </td>
<td><input name="oemail" type="text" id="oemail" size="20" maxlength="30"></td>
</tr>
<tr>
<td>Website Name </td>
<td><input name="wname" type="text" id="wname" size="20" maxlength="20"></td>
</tr>
<tr>
<td>Website Description</td>
<td><input name="wdescription" type="text" id="wdescription" size="20" maxlength="20"></td>
</tr>
<tr>
<td>Website Url </td>
<td><input name="wurl" type="text" id="wurl" size="20" maxlength="75"></td>
</tr>
<tr>
<td>Website Button </td>
<td><input name="wbutton" type="text" id="wbutton" size="20" maxlength="75"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Apply"></td>
</tr>
</table></form>
<?php
if($_POST['Submit']){
include("config.php");
$wb_name = $_POST['oname'];
$wb_email = $_POST['oemail'];
$ws_name = $_POST['wname'];
$ws_desc = $_POST['wdescription'];
$ws_link = $_POST['wurl'];
$ws_button = $_POST['wbutton'];
$ok = mysql_query("INSERT INTO affiliates (id,wb_name,wb_email,ws_name,ws_desc,ws_link,ws_button,state) VALUES('','$wb_name','$wb_email','$ws_name','$ws_desc','$ws_link','$ws_button','0')") or die('Error inserting into DB.');
if($ok){
echo "Thanks for applying $wb_name, you will now be reviewed by the administrator asap.";
}else{
echo "Oops, Error.";
}
};
?>


finally show'em

<?
include "config.php";

$result = mysql_query("SELECT * FROM affiliates WHERE state='1' ORDER BY id ASC");
while($row = mysql_fetch_array($result)){

echo "<p><a href=\"?fd=affiliates&nav=count&outid=".$row['id']."\" target=\"_blank\">
<img src=\"".$row['ws_button']."\" width=88 height=31 title=\"IN: ".$row['countin']." | OUT: ".$row['countout']."\" alt=\"".$row['ws_name']."\" border=\"0\"></a><br>in: " . $row['countin'] . " | out: " . $row['countout'] . "</p>";
}
?>


sorry no time for explain them XD

is like a thanks because of the tutorial
i use it on my site
well i hope it helped you
cya.

edit:
sql:
CREATE TABLE affiliates (
id int(11) NOT NULL auto_increment,
countout smallint(3) NOT NULL,
countin smallint(3) NOT NULL,
wb_name varchar(20) NOT NULL default '',
wb_email varchar(30) NOT NULL default '',
ws_name varchar(20) NOT NULL default '',
ws_desc varchar(20) NOT NULL default '',
ws_link varchar(75) NOT NULL default '',
ws_button varchar(75) NOT NULL default '',
state char(1) NOT NULL default '',
PRIMARY KEY (id),
KEY id (id)
) TYPE=MyISAM;

Edited by fedekiller, 25 April 2006 - 02:42 PM.


#15 SiteReboot

SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 07 October 2006 - 10:39 PM

None of this works at all together.
Better of to just delete this entire post.

#16 Krypton

Krypton

    Young Padawan

  • Members
  • Pip
  • 2 posts

Posted 23 October 2006 - 07:15 PM

How about users can add their site to your affiliates? O_o

#17 Kai Sellgren

Kai Sellgren

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 25 February 2007 - 05:46 PM

Nice job.

I see SQL, CSRF and Header vulnerabilities in this piece of code. Beware of using free scripts or code from tutorials. Better buy a book or go to take a course.

#18 nitr0x

nitr0x

    Young Padawan

  • Members
  • Pip
  • 201 posts

Posted 26 February 2007 - 01:31 PM

Not bad... But it's pretty poorly written. And as for the admin bit, in the apply.php find

$wb_name = $_POST['oname'];
$wb_email = $_POST['oemail'];
$ws_name = $_POST['wname'];
$ws_desc = $_POST['wdescription'];
$ws_link = $_POST['wurl'];
$ws_button = $_POST['wbutton'];
$ok = mysql_query("INSERT INTO affiliates (id,wb_name,wb_email,ws_name,ws_desc,ws_link,ws_button,state) VALUES('','$wb_name','$wb_email','$ws_name','$ws_desc','$ws_link','$ws_button','0')") or die('Error inserting into DB.');

and to make it more secure, update it with

$wb_name = $_POST['oname'];
$wb_email = $_POST['oemail'];
$ws_name = $_POST['wname'];
$ws_desc = $_POST['wdescription'];
$ws_link = $_POST['wurl'];
$ws_button = $_POST['wbutton'];

$wb_email = trim($wb_email);
$ws_name = trim($ws_name);
$ws_desc = trim($ws_desc);
$ws_link = trim($ws_link);
$ws_button = trim($ws_button);

$wb_email = mysql_real_escape_string($wb_email);
$ws_name = mysql_real_escape_string($ws_name);
$ws_desc = mysql_real_escape_string($ws_desc);
$ws_link = mysql_real_escape_string($ws_link);
$ws_button = mysql_real_escape_string($ws_button);

$ok = mysql_query("INSERT INTO affiliates (id,wb_name,wb_email,ws_name,ws_desc,ws_link,ws_button,state) VALUES('','$wb_name','$wb_email','$ws_name','$ws_desc','$ws_link','$ws_button','0')") or die('Error inserting into DB.');

Trim gets rid of white spaces, mysql_real_escape_string makes it safe to insert into the table. PHP.net always advises you to use this when inserting into databases since it helps stops a lot of mysql injections.

Hmm... I feel like writting an affiliate system now. Maybe I will :3




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users