Guest User

Cookies 2.0 *Sorry I fail...*

a guest
Apr 3rd, 2012
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?
  2.  
  3.     /* Start Config */
  4.    
  5.     define("DATABASE_USERNAME", ""); // Database Username
  6.     define("DATABASE_PASSWORD", ""); // Database Password
  7.     define("DATABASE_HOST", "localhost"); // Database Host
  8.     define("DATABASE_NAME", ""); // Database Name
  9.     define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP
  10.    
  11.     /* Database Note:
  12.         Table should be called: cookies
  13.         Two text rows called: ip & cookienum
  14.     */
  15.    
  16.     /* End Config */
  17.    
  18.     /* Connect to database */
  19.     mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
  20.     mysql_select_db(DATABSE_NAME) or die(mysql_error());
  21.    
  22.     /* Check Database For Record */
  23.     $query = mysql_query("SELECT * FROM cookies WHERE ip = '" . REMOTE_IP . "' LIMIT 1");
  24.     $result = mysql_query($query) or die(mysql_error());
  25.    
  26.     /* If the record exists */
  27.     if( $result ){
  28.        
  29.         $row = mysql_fetch_array($result) or die(mysql_error());
  30.         $CLIENT_TOTAL_COOKIES = $row['cookienum'] + 1;
  31.  
  32.         /* Since the record exists, lets update the amount of "cookies" they have */
  33.         if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") ){
  34.             echo "Cookies have been added");
  35.         }else{
  36.             die(mysql_error());
  37.         }
  38.        
  39.     /* If it doesn't exist insert */
  40.     }else{
  41.        
  42.         /* Insert record into database */
  43.         if( mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") ){
  44.             echo "Your record has been added!");
  45.         }else{
  46.             die(mysql_error());
  47.         }
  48.        
  49.     }
  50.    
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment