我創建了一個LoginPage.php用下面的代碼頁之間不宣Session變量仍然
<?
session_start();
if (isset($_SESSION['uid']))
{
header('Location: index.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
include("indexhead.php");
?>
</head>
<body>
<?php
include("myCarousel.php");
echo "
<div class='container'>
<div class='row'>
<div class='col-sm-6 col-md-4 col-md-offset-4'>
<h1 class='text-center login-title'>Sign in to continue:</h1>
<div class='account-wall'>
<form class='form-signin' method='POST'>
<input name='uid' type='text' class='form-control'
placeholder='Username' required autofocus >
<input name='pass' type='password' class='form-control'
placeholder='Password' required >
<button class='btn btn-lg btn-primary btn-block' type='submit'>
Sign in</button>
</form>
</div>
</div>
</div>
</div>
";
if (isset($_POST['uid']) and isset($_POST['pass']))
{
if (empty($_POST['uid']) or empty($_POST['pass']))
{
echo "Please type data into the login";
}
else
{
$uname = stripslashes($_POST['uid']);
$pass = stripslashes($_POST['pass']);
$nick = selectSpecific("select nickName from hera.LoginTable where uid ='".$uname.
"' and pass = md5('".$pass."');");
if ($nick != '')
{
$_SESSION['Nick1'] = selectSpecific("select nickName from hera.LoginTable where uid ='".$uname.
"' and pass = md5('".$pass."');");
$_SESSION['FullName'] = selectSpecific("select FullName from hera.LoginTable where uid ='".$uname.
"' and pass = md5('".$pass."');");
$_SESSION['dept'] = selectSpecific("select dept from hera.LoginTable where uid ='".$uname.
"' and pass = md5('".$pass."');");
$_SESSION['accesslevel'] = selectSpecific("select accesslevel from hera.LoginTable where uid ='".$uname.
"' and pass = md5('".$pass."');");
$_SESSION['uid'] = selectSpecific("select uid from hera.LoginTable where uid ='".$uname.
"' and pass = md5('".$pass."');");
header("Location: index.php");
//echo $_SESSION['Nick1'];
}
else
{
echo "Unknown Username/Password";
}
}
}
?>
</body>
</html>
它的作用是檢查登錄,當登錄成功,用戶被引導到在index.php然而,index.php頁面沒有檢測到$ _SESSION ['']變量,即$_SESSION['uid']
它說:注意:未定義的索引:uid在C:\ xampp \ htdocs \ Hera \ index.php中在線14
但我可以確認會話變量從函數selectSpecific()接收內容。爲什麼會議沒有舉行?
這裏是在index.php
<?php
session_start();
echo $_SESSION['uid'];
?>
而不是使用頁面頂部的頁面回顯$ _SESSION ['uid']並查看它獲得的值 – Dalvik
您可以檢查您的查詢是否可以嗎? 'echo「test =」。 selectSpecific(「select uid from hera.LoginTable where uid ='」。$ uname。 「'and pass = md5('」。$ pass。「'');」);出口; '$ _SESSION ['uid'] = ...'行 – Peter
之前,如果你可以從數據庫中獲取整行,比如'$ _SESSION ['user'] = selectRow(「select * from hera .LoginTable其中uid ='「。$ uname。 」'和pass = md5('「。$ pass。」');「);'(假設你有selectRow函數) – Peter