-
Notifications
You must be signed in to change notification settings - Fork 11
/
validate.php
66 lines (63 loc) · 1.99 KB
/
validate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Use fsock or curl (depending on admin/config.php) to validate the IPN with PayPal
// Once validation is complete we'll have a boolean variabled $valid that we can use throughout the rest of the script.
if(!$curl_validation)
{
// Validate with fsock
if($ssl)
{
$header = '';
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: " . $ppHost . ":443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://' . $ppHost, 443, $errno, $errstr, 30);
}
else
{
$header = '';
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: " . $ppHost . ":80\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ($ppHost, 80, $errno, $errstr, 30);
}
if (!$fp)
$valid = false;
else
{
fputs ($fp, $header . $req);
while(!feof($fp))
{
$res = fgets ($fp, 1024);
if(strcmp ($res, "VERIFIED") == 0)
$valid = true;
elseif (strcmp ($res, "INVALID") == 0)
$valid = false;
}
fclose ($fp);
}
}
else
{
// Validate with curl
$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$ppHost . '/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $ssl);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);
//are we verified? If so, let's process the IPN
if (strpos($curl_result, "VERIFIED")!==false)
$valid = true;
else
$valid = false;
}