Advertisement
Guest User

Untitled

a guest
Apr 4th, 2012
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /* Start Config */
  3.  
  4. define("DATABASE_USERNAME", ""); // Database Username
  5. define("DATABASE_PASSWORD", ""); // Database Password
  6. define("DATABASE_HOST", "localhost"); // Database Host
  7. define("DATABASE_NAME", ""); // Database Name
  8. define("REMOTE_IP", $_SERVER['REMOTE_ADDR']); // Client's IP
  9.  
  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(DATABASE_NAME) or die(mysql_error());
  21.  
  22. /* Check Database For Record */
  23. $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.     /* ECHO: Show client's current cookies */
  39.     echo $CLIENT_TOTAL_COOKIES;
  40.    
  41.     /* If it doesn't exist insert */
  42. } else {
  43.    
  44.     /* Insert record into database */
  45.     if( mysql_query("INSERT IGNORE INTO cookies ( ip, cookienum ) VALUES( '" . REMOTE_IP . "', '1'") )
  46.     echo "Your record has been added!";
  47.     else
  48.     die(mysql_error());
  49. }
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement