您好我正在嘗試在我創建會話的頁面中創建一個表單,因此當我提交表單時會話被破壞這里是我的代碼:
<form method="post">
<h5>Name</h5>
<input type=text name="name" class="insertname">
<br>
<br>
<input type="submit" name="namesearch" class="insertbutton"></input>
</form>';
啟動會話的 PHP 代碼:
<?php
if(isset($_POST['s']))
{
$a=$_POST['uid']; //accessing value from the text field
$enteredpass = $_POST['pwd']; //accessing value from the text field
$client = new MongoDB\Client('xxxx');
$companydb = $client->test;
$jsons = $companydb->jsons;
$ownerid = $jsons->findOne(
['ID' => $a]
);
$idcoded = $ownerid->ID;
if (empty($idcoded)) {
echo "<h1>empty</h1>";
}
if (!empty($idcoded)) {
$passcoded = $ownerid->pass;
if ($passcoded == $enteredpass) {
session_start();
}
}
}
?>
uj5u.com熱心網友回復:
確保你有 session_start(); 在所有 PHP 腳本的頂部
所以,把 session_start(); 在腳本頂部并在用戶正確輸入憑據時設定說 $_SESSION["uid"]
一個正常的做法是$_SESSION["uid"]="";在用戶登錄系統之前設定(設定初始值),然后使用這個會話變數來判斷用戶是否登錄成功。
所以
<?php
session_start();
if(isset($_POST['s']))
{
$a=$_POST['uid']; //accessing value from the text field
$enteredpass = $_POST['pwd']; //accessing value from the text field
$client = new MongoDB\Client('xxxx');
$companydb = $client->test;
$jsons = $companydb->jsons;
$ownerid = $jsons->findOne(
['ID' => $a]
);
$idcoded = $ownerid->ID;
if (empty($idcoded)) {
echo "<h1>empty</h1>";
}
if (!empty($idcoded)) {
$passcoded = $ownerid->pass;
if ($passcoded == $enteredpass) {
$_SESSION["uid"]=$_POST['uid'];
} else {
$_SESSION["uid"]="";
}
}
}
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/519383.html
上一篇:使div內的內容可以滾動
