I'm making a referrer system which will use credits to decide weather or not ads are displayed... If a user has credits, 1 credit is removed per impression and no ad is displayed... If they have no credits, then an ad is displayed... I'd like to make it where a single IP can only count for the loss of a max of 50 credits per day... I've made this much so far: // Connect to database $Database_Host = "********"; $Database_Name = "********"; $Database_Username = "********"; $Database_Password = "********"; $DBConn = mysql_connect($Database_Host, $Database_Username, $Database_Password) or die("Could not connect to database server. Check your settings..."); $DB_DB = mysql_select_db($Database_Name, $DBConn) or die("Could not connect to database ($Database_Name). Perhaps you don't have the right permissions on this DB. Check your settings..."); $query=mysql_query("SELECT adcredits FROM testing"); $query_row=mysql_fetch_array($query); // Generate the ad space... if (($query_row[adcredits]) > 0){ $subtracted = $query_row[adcredits] - 1; $sql = mysql_query("UPDATE testing SET adcredits='$subtracted'"); // Update the database after subtraction echo "No ad will be displayed since they have credits... You have $subtracted left... "; } else { echo "Ad is displayed since you have no credits... <BR>[the ad would go here]"; $sql = mysql_query("UPDATE testing SET adcredits='0'"); // Ensure credit amount isin't a negative number... } PHP: Everything above works fine... But I'd like to add the feature mentioned above... Any ideas? I was thinking maybe cookies... But any working alternative will do fine... Thanks...
I don`t know how could work if you set no username, but i will make the feature you wanted, i hope it works: // Connect to database $Database_Host = "********"; $Database_Name = "********"; $Database_Username = "********"; $Database_Password = "********"; $DBConn = mysql_connect($Database_Host, $Database_Username, $Database_Password) or die("Could not connect to database server. Check your settings..."); $DB_DB = mysql_select_db($Database_Name, $DBConn) or die("Could not connect to database ($Database_Name). Perhaps you don't have the right permissions on this DB. Check your settings..."); $query=mysql_query("SELECT adcredits FROM testing"); $query_row=mysql_fetch_array($query); // Generate the ad space... if(!isset($_COOKIE['visited']) || $_COOKIE['visited'] != 'yes') { if (($query_row[adcredits]) > 0){ $subtracted = $query_row[adcredits] - 1; $sql = mysql_query("UPDATE testing SET adcredits='$subtracted'"); // Update the database after subtraction echo "No ad will be displayed since they have credits... You have $subtracted left... "; } else { echo "Ad is displayed since you have no credits... <BR>[the ad would go here]"; $sql = mysql_query("UPDATE testing SET adcredits='0'"); // Ensure credit amount isin't a negative number... } setcookie('visited','yes',time() + (60*60*24)); } PHP:
It gives this error: Warning: Cannot modify header information - headers already sent by (output started at /home/michael/public_html/test/frontend.php:41) in /home/michael/public_html/test/frontend.php on line 47