Guest User

Cookies :D

a guest
Apr 3rd, 2012
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.36 KB | None | 0 0
  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.     $result = 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.         /* Since the record exists, lets update the amount of "cookies" they have */
  30.         if( mysql_query("UPDATE cookies SET cookienum = cookienum + 1 WHERE ip = '" . REMOTE_IP . "' LIMIT 1") ){
  31.             echo "Cookies have been added");
  32.         }else{
  33.             die(mysql_error());
  34.         }
  35.        
  36.     /* If it doesn't exist insert */
  37.     }else{
  38.        
  39.         /* Insert record into database */
  40.         if( mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") ){
  41.             echo "Your record has been added!");
  42.         }else{
  43.             die(mysql_error());
  44.         }
  45.        
  46.     }
  47.    
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment