...

View Full Version : Referral Links



Xibe
08-09-2007, 06:02 AM
Hey,

Im trying to make a referral script that will log how many individual visitors a person has referred with their link. For instance: they sign up for the referral program and get their own link:

If someone goes to this link:

http://mysite.com/index.php?=Xibe

Then it would check the person's IP (to see if they have already been counted in the referral system before), then if they haven't been counted... it would log one new click for the user: Xibe.

How can I make something like this?

Thanks,
X

usik
08-09-2007, 09:18 AM
Hey why don't you try something like this



<?php
if(isset($_GET["user"]))
{
if(empty($_GET["user"]))
{
die("User must be selected");
}

$user = $_GET["user"];
$ip = GetHostByName($_SERVER["REMOTE_ADDR"]);

$connect = mysql_connect("my_server", "my_username", "my_password");
mysql_query("my_db", $connect) or die(mysql_error());

$sql = "INSERT INTO referals (username, ip) VALUES ('$user', '$ip')";
mysql_query($sql) or die(mysql_error());
}
?>


just make sure the ip address field is set as the primary key or as unique to avoid same ip addresses adding to the users referral count.

StupidRalph
08-09-2007, 09:27 AM
Hey why don't you try something like this



<?php
if(isset($_GET["user"]))
{
if(empty($_GET["user"]))
{
die("User must be selected");
}

$user = $_GET["user"];
$ip = GetHostByName($_SERVER["REMOTE_ADDR"]);

$connect = mysql_connect("my_server", "my_username", "my_password");
mysql_select_db("my_db", $connect) or die(mysql_error()); //you had query here.

$sql = "INSERT INTO referals (username, ip) VALUES ('$user', '$ip')";
mysql_query($sql) or die(mysql_error());
}
?>


just make sure the ip address field is set as the primary key or as unique to avoid same ip addresses adding to the users referral count.
You accidentally used mysql_query twice and meant to use select db

usik
08-09-2007, 10:44 AM
lol thanks was testing the example on my laptop but was on the forum on another computer so i had to write it in manually and im used to typing mysql_query alot more than mysql_connect_db :p



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum