Advertisement
gordyknows

Untitled

Feb 17th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. mysql_connect("localhost", "root", "jeh35795") or die(mysql_error());
  3. mysql_select_db("de4") or die(mysql_error());
  4.  
  5. // read the post from PayPal system and add 'cmd'
  6. $req = 'cmd=_notify-validate';
  7. foreach ($_POST as $key => $value) {
  8. $value = urlencode(stripslashes($value));
  9. $req .= "&$key=$value";
  10. }
  11. // post back to PayPal system to validate
  12. $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
  13. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  14. $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  15.  
  16. //$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
  17. $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
  18.  
  19. if (!$fp) {
  20. // HTTP ERROR
  21. } else {
  22. fputs ($fp, $header . $req);
  23. while (!feof($fp)) {
  24. $res = fgets ($fp, 1024);
  25. if (strcmp ($res, "VERIFIED") == 0) {
  26. // PAYMENT VALIDATED & VERIFIED!
  27. if ($_POST['payment_status'] == 'Completed') {
  28. //This is the array where we get the items
  29. $item_number = array();
  30. //Counter (must be on 1 from default or it will drop errors)
  31. $x = 1;
  32. //Adding every item to the $item_number array
  33. while(isset($_POST["item_number$x"])){
  34.  
  35. $id = $_POST["item_number$x"];
  36. $username = $_POST["option_selection1_$x"];
  37. for ($i= 1; $i<=$_POST["quantity$x"]; $i ++){
  38. $sql = "INSERT INTO payments (id, username) VALUES(". mysql_escape_string($id) .", '". mysql_escape_string($username)."' ) ";
  39. mysql_query($sql) or die(mysql_error());
  40. }
  41.  
  42. $f = fopen("iphoutput.txt", "a+");
  43. fwrite($f, $sql);
  44. fclose($f);
  45.  
  46. /* $qty = $_POST["quantity$x"];
  47. while($qty > 0){
  48. $item_number[$x] = $_POST["item_number$x"];
  49. $qty--;
  50. }*/
  51. $x++;
  52. }
  53.  
  54.  
  55. //final entry
  56. //mysql_query("INSERT INTO payments (id, username) VALUES(". mysql_escape_string($id) .", '". mysql_escape_string($username)."' ) ") or die(mysql_error());
  57.  
  58. }
  59. }
  60.  
  61. else if (strcmp ($res, "INVALID") == 0) {
  62. // PAYMENT INVALID & INVESTIGATE MANUALY!
  63.  
  64. }
  65. }
  66. fclose ($fp);
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement