Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-09-2007, 05:02 AM   PM User | #1
Xibe
New Coder

 
Join Date: Nov 2005
Posts: 66
Thanks: 8
Thanked 0 Times in 0 Posts
Xibe is an unknown quantity at this point
Referral Links

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:
Code:
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
Xibe is offline   Reply With Quote
Old 08-09-2007, 08:18 AM   PM User | #2
usik
New Coder

 
Join Date: Aug 2007
Location: Wagga, Australia
Posts: 59
Thanks: 0
Thanked 1 Time in 1 Post
usik is on a distinguished road
Hey why don't you try something like this

PHP Code:
<?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.
usik is offline   Reply With Quote
Old 08-09-2007, 08:27 AM   PM User | #3
StupidRalph
Senior Coder

 
Join Date: Mar 2003
Location: Atlanta
Posts: 1,037
Thanks: 14
Thanked 30 Times in 28 Posts
StupidRalph is on a distinguished road
Thumbs up

Quote:
Originally Posted by usik View Post
Hey why don't you try something like this

PHP Code:
<?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
__________________
Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.
StupidRalph is offline   Reply With Quote
Old 08-09-2007, 09:44 AM   PM User | #4
usik
New Coder

 
Join Date: Aug 2007
Location: Wagga, Australia
Posts: 59
Thanks: 0
Thanked 1 Time in 1 Post
usik is on a distinguished road
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
usik is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:59 PM.


Advertisement
Log in to turn off these ads.