我可以创建一个仅对 PayPal 付款的人可见的页面吗?
我正在寻找用户在访问页面之前进行付款,如果有人尝试在未付款的情况下查看该页面,他们将被重定向到错误页面
这甚至是一个简单的任务吗?如果是这样,我将如何进行设置?是否有在线教程?
这只是我正在创建的一个简单的 2 页网站。没什么复杂的......
我刚才使用的是标准 PayPal 按钮,但我不确定它是否那么简单
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="V6RE5BUJCBAPU">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal — The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
最佳答案
一个可能的解决方案确实是创建一个 PayPal 按钮。用户付款后,您可以将他/她重定向到自定义页面,告诉他们已成功付款。您可以让PayPal将付款数据发布到此页面,您可以通过这种方式验证付款确实已成功完成。
如果是这样,您可以设置 SESSION 或 COOKIE 变量,并在“目标”页面(他们只能在付款后才能访问的页面)上验证 SESSION 或 COOKIE 是否已设置。如果没有,请将他们重定向到付款页面。
示例
利用类似的东西:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="return" value="http://www.yourwebsite.com/index.php?payment=success" />
</form>
因此,付款完成后,用户将被重定向到 index.php? payment=success,您可以在其中阅读来自 PayPal 的帖子:
<?php
$req = "cmd=_notify-synch";
$tx_token = $_GET['tx'];
$auth_token = "<your auth token here>";
$req .= "&tx=$tx_token&at=$auth_token";
//Post back to Paypal system to validate:
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
//HTTP ERROR
}
else {
fputs($fp, $header . $req);
//Read body data:
$res = '';
$headerdone = false;
while (!feof($fp)) {
$line = fgets($fp, 1024);
if (strcmp($line, "\r\n") == 0) {
$headerdone = true;
}
else{
$res .= $line;
}
}
//Parse the data:
$lines = explode("\n", $res);
$keyarray = array();
if (strcmp($lines[0], "SUCCESS") == 0) {
//Checks the payment_status is completed
//check that txn_id has not been previously processed
for ($i = 0; $i < count($lines); $i++) {
list($key, $val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
}
//Process payment:
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
//etc... you can either insert the payment data into your database for future reference
//Or set up a COOKIE for the user to be able to download your file.
//Or if your payment has been successful, redirect him to a "secret" page where the file is visible.
}
?>
关于php - paypal付款后才访问页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6980553/