Guest User

Untitled

a guest
Dec 5th, 2018
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.19 KB | None | 0 0
  1. Setup database as follows:
  2. -----------------------------
  3. | id   email   string   used|
  4. -----------------------------
  5.  
  6. The `used` column is used (lol) to see if the code has been used (lol) yet
  7. It's there just in case the row DOESN'T delete due to an error. If someone
  8. tries to reuse the same code, it won't work because the value will be 1 instead
  9. of the normal inputted 0.
  10. <?php
  11.     function safeEmail($email) {
  12.     $email = eregi_replace('#','', $email);
  13.     $length = strlen($email);
  14.     for ($i = 0; $i < $length; $i++)
  15.         $obfuscatedEmail .= "&#" . ord($email[$i]);  // creates ASCII HTML entity
  16.     $return = '<a href="mailto:' . $obfuscatedEmail . '">'.$obfuscatedEmail.'</a>';
  17.     return $return;
  18.     }
  19.    
  20.     function check4email($string){
  21.     $pattern = "#[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})#";
  22.     preg_match_all($pattern, $string, $split);
  23.     foreach ($split[0] as $value) {
  24.         $email_to_find = '#' . $value . '#';
  25.         $string = eregi_replace($email_to_find,safeEmail($value),$string);
  26.     }
  27.     return $string;
  28.     }
  29.  
  30. ?>
  31. <?php
  32.     //Housekeeping connectivity crap...
  33.     $mysql_host = '';
  34.     $mysql_username = '';
  35.     $mysql_password = '';
  36.     $db = '';
  37.    
  38.     mysql_connect($mysql_host,$mysql_username,$mysql_password);
  39.     mysql_select_db($db);
  40.    
  41.     $e = $_GET['e'];
  42.     $c = $_GET['c'];
  43.    
  44.     if(($e != "") && ($c != "")){
  45.         $sql = "SELECT * FROM `donate` WHERE email = '$e' AND string = '$c'";
  46.         if(mysql_num_rows($sql) != 1){
  47.             die("ERROR: invalid values");
  48.         } else {
  49.             $email = check4email($e);
  50.             $sql2 = "UPDATE `donate` SET used = 1 WHERE email = '$e' AND string = '$c'";
  51.             $sql3 = "DELETE FROM `donate` WHERE email = '$e' AND string = '$c' LIMIT 1";
  52.             if((mysql_query($sql2)) && (mysql_query($sql3))){
  53.                 //*******************************
  54.                 //
  55.                 //PUT CODE HERE TO UPGRADE PERSON
  56.                 //
  57.                 //*******************************
  58.                 mail($email, 'Upgrade', 'You have been upgraded!', 'From: service@paypal.com');
  59.             } else {
  60.                 die("There was an error. Please try your request again.");
  61.             }
  62.         }
  63.     } else {
  64.         //This variable has to come from somewhere else...maybe some post data?
  65.         $email = 'guitarman0831@aol.com';
  66.    
  67.         //The encoded email address, to be written to DB and in url
  68.         $emailencode = safeEmail($email);
  69.    
  70.         //URL to send the donator
  71.         //Use e as email and c as code, to avoid figuring out what the URL means
  72.         $url = 'whateverdomain.com?e=' . $emailencode . '&c=' . $string;
  73.    
  74.         //Create your own message for the email, just putting this one for now
  75.         $message = "Thank you for donating! Your unique link is " + $url;
  76.    
  77.         //Subject!
  78.         $subject = "Donation";
  79.        
  80.         //Who should the email be from?
  81.         $from = 'service@paypal.com'; //lol
  82.    
  83.         //Generate MD5 string!
  84.         $length = 10;
  85.         $characters = ‘0123456789abcdefghijklmnopqrstuvwxyz’;
  86.         for ($p = 0; $p < $length; $p++) {
  87.             $string .= $characters[mt_rand(0, strlen($characters))];
  88.         }  
  89.    
  90.         $sql = "INSERT INTO `donate` VALUES ('','$emailencode','$string','0')";
  91.         if(mysql_query($sql)){
  92.             mail($email, $subject, $message, "From: " . $from);
  93.             die("Thank you for the donation!");
  94.         } else {
  95.             die("Oops! Something went wrong! Please try your query again.");
  96.         }
  97.     }
  98. ?>
Add Comment
Please, Sign In to add comment