function.php WordPress中的会话问题

时间:2015-10-28 10:05:06

标签: php wordpress session paypal paypal-ipn

我是WordPress的新手。我在IPN中有PayPal代码function.php。我为此创建了一个钩子。现在我的问题是我没有在这个钩子中收到会话值。我尝试了所有选项,如

  1. wp-config.phpsession_start()
  2. 中执行代码
  3. wp-settings.php$noUnset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES', 'table_prefix', '_SESSION');
  4. 中执行代码
  5. 也会在两个文件中启动会话(在我的钩子和其他文件中)
  6. 还尝试了会话插件。
  7. 也在function.php完成了代码            (

            if (!session_id()) {
               session_start();
            }
    
            function sess_start() { 
              if (!session_id()) 
                session_start(); 
            } 
            add_action('init','sess_start');
    
           )
    
  8. 这是我的代码:

     add_action('paypal_ipn_for_wordpress_payment_status_completed', 'process_payment', 10, 1);
     function process_payment( $posted )
     { 
       if( !session_id())
        session_start();
    
    $email12 = $_SESSION['email12'];   
    // Parse data from IPN $posted[] array
    $first_name = isset($posted['first_name']) ? $posted['first_name'] : '';
    $last_name = isset($posted['last_name']) ? $posted['last_name'] : '';
    $payment_amount = isset($posted['mc_gross']) ? $posted['mc_gross'] : '';
    $recurring_payment_id = isset($posted['recurring_payment_id']) ? $posted['recurring_payment_id'] : '';
    $payer_email = isset($posted['payer_email']) ? $posted['payer_email'] : '';
    $txn_id = isset($posted['txn_id']) ? $posted['txn_id'] : '';
    $receiver_email= isset($posted['receiver_email']) ? $posted['receiver_email'] : '';   
        $mail_From    = $payer_email;
        $mail_To      = $receiver_email;
        $mail_Subject = "VERIFIED IPN";
        $mail_Body    = "Hello Secretary,
                     New registration for the event: 
                         Name: $first_name $last_name";
     mail($mail_To, $mail_Subject, $mail_Body, $mail_From);   
        $mail_From    = $receiver_email;
        $mail_To      = $payer_email;
        $mail_Subject = "VERIFIED IPN";
        $mail_Body    = "Thank you for registration. Your registration has been successfully done.";
    mail($mail_To, $mail_Subject, $mail_Body, $mail_From);       
     global $wpdb; 
         $id12 = $wpdb->get_results("SELECT * FROM wp_tmpnonmembersdetail");
    
        foreach($id12 as $row1)
     {
    $wpdb->insert( wp_checkoutnonmembersdetails, array( 
                                'Event_Name' => $row1->Event_Name,
                                'Event_Date' => $row1->date,
                'First_Name' => $row1->First_Name,
                'Last_Name' => $row1->Last_Name, 
                'Address' => $row1->Address, 
                'Email' => $email12  , 
                'cellphone' => $row1->cellphone, 
                'quantity' => $row1->quantity,
                                'reg_date' => $row1->date,
                                'payment_amount' => $payment_amount
        ) );
      }
    
    
    $id22 = $wpdb->get_results("SELECT * FROM wp_tmpmembersdetail where  id = '$id1' ");
    foreach($id22 as $row2)
    {
    $wpdb->insert( wp_checkouttmpmembersdetail, array( 
                                'Event_Name' => $row2->Event_Name,
                'First_Name' => $row2->First_Name,
                'Last_Name' => $row2->Last_Name, 
                'Address' => $row2->Address, 
                'Email' => $row2->Email, 
                'cellphone' => $row2->cellphone, 
                'quantity' => $row2->quantity,
                                'payment_amount' => $payment_amount
        ) );
        } 
      }
    

    另一个奇怪的事情是我在另一个钩子中的同一个function.php文件中得到了另一个会话。 请帮助我。

1 个答案:

答案 0 :(得分:0)

我没有得到确切的会话问题。但是,我想问两件事 - 1.您在哪个页面或功能中创建这3个会话($ _SESSION ['email'])?

  1. 在下面的代码中你写了错误的变量名 - 我想它应该是$ email而不是$ email12
  2. $ id12 = $ wpdb-> get_results(“SELECT * FROM table_name where Email ='$ email12'”);

    $ _ SESSION变量值只能在创建后检索。如果您已手动编写此代码,则必须编写/创建这些$ _SESSION变量。

    如果它是插件并且您不知道从哪里获得 - 请尝试在插件文件中搜索$ _SESSION ['email'] =代码或文本。

    让我知道。

    最佳,

    Bhargav