Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Start Config */
- define("DATABASE_USERNAME", ""); // Database Username
- define("DATABASE_PASSWORD", ""); // Database Password
- define("DATABASE_HOST", "localhost"); // Database Host
- define("DATABASE_NAME", ""); // Database Name
- define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP
- /**
- * Database Note:
- * Table should be called: cookies
- * Two text rows called: ip & cookienum
- */
- /* End Config */
- /* Connect to database */
- mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
- mysql_select_db(DATABASE_NAME) or die(mysql_error());
- /* Check Database For Record */
- $query = "SELECT * FROM cookies WHERE ip = '" . REMOTE_IP . "' LIMIT 1";
- $result = mysql_query($query) or die(mysql_error());
- /* If the record exists */
- if( $result ){
- $row = mysql_fetch_array($result) or die(mysql_error());
- $CLIENT_TOTAL_COOKIES = $row['cookienum'] + 1;
- /* Since the record exists, lets update the amount of "cookies" they have */
- if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") )
- echo "Cookies have been added";
- else
- die(mysql_error());
- /* ECHO: Show client's current cookies */
- echo $CLIENT_TOTAL_COOKIES;
- /* If it doesn't exist insert */
- } else {
- /* Insert record into database */
- if( mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") )
- echo "Your record has been added!";
- else
- die(mysql_error());
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement