亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHP 中的變量在 ajax 請求后丟失

PHP 中的變量在 ajax 請求后丟失

PHP
慕碼人8056858 2022-08-19 10:14:32
我的目標 - 通過條紋或PayPal付款,一旦完成,向客戶出示一份表格,上傳文件以通過電子郵件發送給我。我的表單處于自舉模態中。我正在嘗試確保除非付款,否則無法提交表單。客戶當前付款,由 ajax 完成。這工作正常,并顯示付款ID。但是,當我向同一 php 文檔發送另一個 ajax 請求時,要完成電子郵件發送,使用 ,該變量已丟失其值。$send_form = $_POST["email_form"];$payment_made<?php$send_form = $_POST["email_form"]; //this is sent by ajax. Will be 'yes' if the form to send has been submitted.switch ($action){  case 'stripe':    //do stripe transaction    //set a variable to indicate payment is complete using transaction ID    $payment_made = $transaction->id;  break;  case 'paypal':    //do paypal transaction    //set a variable to indicate payment is complete using transaction ID    $payment_made = $transaction->id;  break;}function sendmail() {  //usual php mail function (works fine)}if ($send_form = 'yes' && $payment_made != '') {  sendmail();}?>我的問題:如何使用變量來驗證付款是否已完成,以防止未經授權使用電子郵件表單?$payment_made除非有要求,否則我不會上傳ajax或html代碼,因為它都可以正常工作,只要我在使用之前不檢查變量。$payment_madephpmail()
查看完整描述

1 回答

?
繁花不似錦

TA貢獻1851條經驗 獲得超4個贊

我使用PHP會話來存儲然后刪除變量。


<?php

session_start();

$send_form = $_POST["email_form"]; //this is sent by ajax. Will be 'yes' if the form to send has been submitted.


switch ($action){

  case 'stripe':

    //do stripe transaction

    //set a variable to indicate payment is complete using transaction ID

    $_SESSION["payment_made"] = $transaction->id;

  break;

  case 'paypal':

    //do paypal transaction

    //set a variable to indicate payment is complete using transaction ID

    $_SESSION["payment_made"] = $transaction->id;

  break;

}


function sendmail() {

  //usual php mail function (works fine)

  session_unset();

  session_destroy();

  mail();

}


if ($send_form = 'yes' && $_SESSION["payment_made"] != '') {

  sendmail(); 

}

?>


查看完整回答
反對 回復 2022-08-19
  • 1 回答
  • 0 關注
  • 94 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號