|
| 1 | +<?php |
| 2 | + |
| 3 | +mysql_connect("localhost", "root", "") or die(mysql_error()); |
| 4 | +mysql_select_db("db_nepalstay") or die(mysql_error()); |
| 5 | + |
| 6 | + |
| 7 | +// read the post from PayPal system and add 'cmd' |
| 8 | +$req = 'cmd=_notify-validate'; |
| 9 | +foreach ($_POST as $key => $value) { |
| 10 | +$value = urlencode(stripslashes($value)); |
| 11 | +$req .= "&$key=$value"; |
| 12 | +} |
| 13 | +// post back to PayPal system to validate |
| 14 | +$header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; |
| 15 | +$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
| 16 | +$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; |
| 17 | + |
| 18 | +$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); |
| 19 | + |
| 20 | + |
| 21 | +if (!$fp) { |
| 22 | +// HTTP ERROR |
| 23 | +} else { |
| 24 | +fputs ($fp, $header . $req); |
| 25 | +while (!feof($fp)) { |
| 26 | +$res = fgets ($fp, 1024); |
| 27 | +if (strcmp ($res, "VERIFIED") == 0) { |
| 28 | + |
| 29 | +// PAYMENT VALIDATED & VERIFIED! |
| 30 | + |
| 31 | +$email = $_POST['payer_email']; |
| 32 | +$password = mt_rand(1000, 9999); |
| 33 | + |
| 34 | +mysql_query("INSERT INTO users (stay_email, user_pass_md5) VALUES('". mysql_escape_string($email) ."', '".md5($password)."' ) ") or die(mysql_error()); |
| 35 | + |
| 36 | +$to = $email; |
| 37 | +$subject = 'Download Area | Login credentials'; |
| 38 | +$message = ' |
| 39 | +
|
| 40 | +Thank you for your purchase |
| 41 | +
|
| 42 | +Your account information |
| 43 | +------------------------- |
| 44 | +Email: '.$email.' |
| 45 | +Password: '.$password.' |
| 46 | +------------------------- |
| 47 | + |
| 48 | +You can now login at http://yourwebsite.com/PayPal/'; |
| 49 | +$headers = 'From:noreply@downloadarea.com' . "\r\n"; |
| 50 | + |
| 51 | +mail($to, $subject, $message, $headers); |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +} |
| 56 | + |
| 57 | +else if (strcmp ($res, "INVALID") == 0) { |
| 58 | + |
| 59 | +// PAYMENT INVALID & INVESTIGATE MANUALY! |
| 60 | + |
| 61 | +$to = 'admin@yourwebsite.com'; |
| 62 | +$subject = 'Download Area | Invalid Payment'; |
| 63 | +$message = ' |
| 64 | +
|
| 65 | +Dear Administrator, |
| 66 | +
|
| 67 | +A payment has been made but is flagged as INVALID. |
| 68 | +Please verify the payment manualy and contact the buyer. |
| 69 | +
|
| 70 | +Buyer Email: '.$email.' |
| 71 | +'; |
| 72 | +$headers = 'From:noreply@yourwebsite.com' . "\r\n"; |
| 73 | + |
| 74 | +mail($to, $subject, $message, $headers); |
| 75 | + |
| 76 | +} |
| 77 | +} |
| 78 | +fclose ($fp); |
| 79 | +} |
| 80 | +?> |
0 commit comments