Php 贝宝数据传输后直接转到新的html页面
当用户完成paypal交易时,它会将他们发送到我网站上处理交易的页面。然而,屏幕是白色的,没有源代码出现。我知道在数据库更新时,脚本正在运行SQL语句。然后,脚本应该直接指向页面,如其标题输出所示,但我想知道,既然Paypal对该页面进行了两次访问,这可能会把事情搞砸 以下是返回脚本:Php 贝宝数据传输后直接转到新的html页面,php,paypal,Php,Paypal,当用户完成paypal交易时,它会将他们发送到我网站上处理交易的页面。然而,屏幕是白色的,没有源代码出现。我知道在数据库更新时,脚本正在运行SQL语句。然后,脚本应该直接指向页面,如其标题输出所示,但我想知道,既然Paypal对该页面进行了两次访问,这可能会把事情搞砸 以下是返回脚本: <?php error_reporting(E_ALL); ini_set('display_errors', 1); // The custom hidden field
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
// The custom hidden field (user id) sent along with the button is retrieved here.
if($_GET['cm']) $user=$_GET['cm'];
// The unique transaction id.
if($_GET['tx']) $tx= $_GET['tx'];
$identity = 'TOKEN VALUE';
// Init curl
$ch = curl_init();
// Set request options
curl_setopt_array($ch, array ( CURLOPT_URL => 'https://www.paypal.com/cgi-bin/webscr',
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => http_build_query(array
(
'cmd' => '_notify-synch',
'tx' => $tx,
'at' => $identity,
)),
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
// CURLOPT_SSL_VERIFYPEER => TRUE,
// CURLOPT_CAINFO => 'cacert.pem',
));
// Execute request and get response and status code
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// Close connection
curl_close($ch);
if($status == 200 AND strpos($response, 'SUCCESS') === 0)
{
include ("dbconnect.php");
$query="UPDATE users SET paid='1' WHERE userid='$user'";
$result=mysqli_query($con,$query);
exit(); // Quit the script.
header('Location: http://www.xxxxxxxxxxx/php/process_paypal_success.php');
}
?>
您在标头之前退出,因此不会发生重定向
一旦你退出,就这样;其余代码将不会执行
因此,请更改脚本的这一部分:
exit(); // Quit the script.
header('Location: http://www.xxxxxxxxxxx/php/process_paypal_success.php');
致:
放置exit()代码>在标题后面
参考:
退出-输出消息并终止当前脚本
旁注:您也可以使用exit代码>,不需要()
除非您想显示一条消息:
or exit("unable to open file ($filename)");
从手册^
因此,在您的情况下,您不能显示其他消息,因为您使用的是标题
脚注:
您的代码易于SQL注入。最好是使用事先准备好的声明
参考:
在打开PHP标记后立即将错误报告添加到文件顶部,例如它已经存在,在黑暗中浏览快照时不会出现任何错误;尝试放置exit()代码>在标题后面。我不确定这是否有什么不同,但我习惯于这样使用/看待它。@Fred ii-就是这样@Rhillz很好,很高兴听到,干杯
header('Location: http://www.xxxxxxxxxxx/php/process_paypal_success.php');
exit(); // Quit the script.
or exit("unable to open file ($filename)");