第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在 HTML 表單操作之前運(yùn)行 PHP 提交代碼以設(shè)置 SESSION 變量

在 HTML 表單操作之前運(yùn)行 PHP 提交代碼以設(shè)置 SESSION 變量

PHP
胡子哥哥 2023-08-11 16:57:37
當(dāng)用戶提交 HTML 表單時(shí),有沒有辦法在執(zhí)行 HTML 表單的操作并離開頁面之前運(yùn)行將表單數(shù)據(jù)保存為會(huì)話變量所需的 PHP 代碼?當(dāng)我將表單操作設(shè)置為轉(zhuǎn)到下一頁 (session2.php) 時(shí),它會(huì)在不運(yùn)行與提交按鈕關(guān)聯(lián)的 PHP 的情況下執(zhí)行此操作。如果我刪除表單操作,那么我需要 PHP 提交腳本中的 JavaScript 將用戶帶到下一頁。有沒有辦法先運(yùn)行 PHP,然后運(yùn)行表單操作,還是最好保持原樣?我確實(shí)有session_start(); 作為兩個(gè)文件中的第 1 行。會(huì)話1.php<?phpif (isset($_POST['submit'])) {      // Set Global Session Variables from Form's POST Values    $_SESSION["favcolor"] = $_POST['favcolor'];    $_SESSION["favanimal"] = $_POST['favanimal'];        // Go To Next Page    $URL="session2.php";    echo "<script type='text/javascript'>document.location.href='{$URL}';</script>";    echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';}       ?><form action="" method="post">Enter Color: <input type="text" name="favcolor" /><br />Enter Animal: <input type="text" name="favanimal" /><br /><input type="submit" value="submit" name="submit" /></form>會(huì)話2.php<?php// Echo session variables that were set on previous pageecho "Favorite color is " . $_SESSION["favcolor"] . ".<br>";echo "Favorite animal is " . $_SESSION["favanimal"] . ".";?>
查看完整描述

1 回答

?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊

有幾種方法可以做到這一點(diǎn):

  1. 使用 PHP 的header('Location: /page-url');

  2. $_POST如果設(shè)置則渲染不同的內(nèi)容

<?php


if (isset($_POST['submit'])) {  


    // Set Global Session Variables from Form's POST Values

    $_SESSION["favcolor"] = $_POST['favcolor'];

    $_SESSION["favanimal"] = $_POST['favanimal'];

    

    // Render other page content

    include "session2.php";

    

    // end the script to prevent loading this page contents

    die;

}       

?>



<form action="" method="post">

Enter Color: <input type="text" name="favcolor" /><br />

Enter Animal: <input type="text" name="favanimal" /><br />

<input type="submit" value="submit" name="submit" />

</form>

通過 AJAX 請(qǐng)求提交表單并根據(jù)響應(yīng)進(jìn)行重定向


查看完整回答
反對(duì) 回復(fù) 2023-08-11
  • 1 回答
  • 0 關(guān)注
  • 122 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)