<?php
$host = "localhost";
$username = "XXXXXXXXXXX"; //Set this to your mysql username
$password = "XXXXXXXXXXXXX"; //Set this to your mysql password
$dbname = "XXXXXXXXXXXX"; //Set this to your mysql database name
$tblname = "XXXXXXXXXXXXXX"; //Set this to your table name
$ip_address = $_SERVER["REMOTE_ADDR"]; //Gets ip address
$offer = "XXXXXXX" //Set this to the offer being displayed
//******************************************
//Sees if the visitor has previously visited the page
//------------------------------------------
mysql_connect ($host, $username, $password)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$query="select ip from $tblname WHERE ip = '$ip_address'"; // query string stored in a variable
$rt=mysql_query($query); // query executed
echo mysql_error(); // if any error is there that will be printed to the screen
$check_repeat_visitor = 0;
if($rt){ $check_repeat_visitor = mysql_num_rows($rt);}
//If visitor is unique record their IP and the offer shown
if($check_repeat_visitor == 0){
$viewer_new_query = "INSERT INTO $tblname (ip, offer) VALUES
('$ip_address', '$offer')";
$viewer_new_result = mysql_query($viewer_new_query);
}
//If visitor is not unique get the offer they were shown
if($check_repeat_visitor != 0){
$checkHits = "SELECT offer FROM $tblname WHERE ip = '$ip_address'";
$checkHitsResult=mysql_query($checkHits);
$row = mysql_fetch_array($checkHitsResult);
$offer = $row["offer"];
}
?>