在paypal数据传输后直接进入新的html页面

时间:2015-10-10 20:52:50

标签: php paypal

当用户完成paypal交易时,它会将其发送到我网站上处理交易的页面。但是屏幕是白色的,没有源代码。我知道脚本正在使用SQL语句,因为我的数据库正在更新。然后,脚本应该按照其标题输出指示页面,但我想知道,因为Paypal对此页面进行两次访问可能会弄乱这一点。

这是返回脚本:

        <?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');
    }
    ?>

这里是返回脚本应该向用户发送的页面:

          <?php 
      ob_start();
      session_start();
      require_once ('verify.php'); 
      $page_title = 'settings.php';


      $sid = session_id();
      $first_name=$_SESSION['first_name'];
      $last_name=$_SESSION['last_name'];
      $email_address=$_SESSION['email_address'];


              include ("dbconnect.php");
              $query="SELECT * FROM users WHERE email_address='$email_address'";
              $result=mysqli_query($con,$query);
              $data=mysqli_fetch_assoc($result);
                  $userid = $data['userid'];
                  $password = $data['password'];
                  $signup_date = $data['signup_date'];
                  $last_login = $data['last_login'];

      // Check for a $page_title value:
      if (!isset($page_title)) {
          $page_title = 'User Registration';
      }

      // If no first_name session variable exists, redirect the user:
      if (!isset($_SESSION['email_address'])) {

          $url = BASE_URL . ''; // Define the URL.
          ob_end_clean(); // Delete the buffer.
          header("Location: $url");
          exit(); // Quit the script.

      }
      ?>
      <?php 
      $title="title here" ; 
      $description="You have successfully submitted your payment and registered for the event" ; 
      include( "header.php"); 
      ?>
      <body>

  

1 个答案:

答案 0 :(得分:2)

您在标题之前退出,因此重定向不会发生。

一旦你退出,就是这样;其余代码将无法执行。

因此,请更改脚本的这一部分:

exit(); // Quit the script.
header('Location: http://www.xxxxxxxxxxx/php/process_paypal_success.php');

为:

header('Location: http://www.xxxxxxxxxxx/php/process_paypal_success.php');
exit(); // Quit the script.

在标题后放置exit();

参考:

  

退出 - 输出消息并终止当前脚本

旁注:您也可以使用exit;,不需要()

除非您想要显示消息:

or exit("unable to open file ($filename)");

来自手册^

因此,在您的情况下,由于您使用的是标题,因此无法显示其他消息。

脚注:

您的代码很容易注入SQL。如果您使用准备好的声明,那将是最好的。

参考: