查看我认为相关的所有其他PHP Session页面,并且无法找到我的页面上的问题。以下是我的3页代码:
Login.htm(可行)
<body>
<section class="container">
<div class="login">
<h1>Login to Web App</h1>
<form method="post" action="checklogin.php">
<p><input type="text" name="login" value="" placeholder="Username or Email"></p>
<p><input type="password" name="password" value="" placeholder="Password"></p>
<p class="remember_me">
<label>
<input type="checkbox" name="remember_me" id="remember_me">
Remember me on this computer
</label>
</p>
<p class="submit"><input type="submit" name="commit" value="Login"></p>
</form>
</div>
<div class="login-help">
<p>Forgot your password? <a href="index.html">Click here to reset it</a>.</p>
</div>
</section>
<section class="about">
<p class="about-links">
<a href="http://www.cssflow.com/snippets/login-form" target="_parent">View Article</a>
<a href="http://www.cssflow.com/snippets/login-form.zip" target="_parent">Download</a>
</p>
<p class="about-author">
© 2012–2013 <a href="http://thibaut.me" target="_blank">Thibaut Courouble</a> -
<a href="http://www.cssflow.com/mit-license" target="_blank">MIT License</a><br>
Original PSD by <a href="http://www.premiumpixels.com/freebies/clean-simple-login-form-psd/" target="_blank">Orman Clark</a>
</section>
</body>
checklogin.php(这样可行,会话已成功创建,您可以在代码中查看我的测试以确保会话实际设置)
<?php
session_start();
$con=mysqli_connect("someServer","root","somePassword","someDatabase");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Get the two variables for login and password from the form on login.htm
$user = $_POST['login'];
$password = $_POST['password'];
//Write out your MySql Query
$result = mysqli_query($con,"SELECT * FROM members where username = '$user' and password = '$password'");
//Get the row number your query sends out. This is to make sure the username / password combo actually exist
$num_row = mysqli_num_rows($result);
if ( $num_row == 1 )
{
while($row = mysqli_fetch_array($result)) {
//Get the data from MySQL
echo $row['username'] . " " . $row['password'];
//Set whatever is in username to the variable $user1
$user1 = $row['username'];
echo "<br>";
echo $user1;
echo "<br>";
//Start Sessions
//set the session username5 to whatever was in the SQL table for user
$_Session['username5'] = $user1;
//Read off the session stored variable
echo $_Session['username5'];
}
} else {
echo 'That shit didnt work';
}
// rest of page . .
if ($_Session['username5']) {
header( 'Location: https://localhost/avesi/login_success.php' ) ;
}else{
echo "Login Failed!";
}
mysqli_close($con);
?>
Login_success.php(这是我收到错误的地方 - 注意:未定义的变量:第10行的C:\ xampp \ htdocs \ avesi \ login_success.php中的_Session)
<?php
session_start();
echo time();
if (!empty($_SESSION['username5'])) {
echo "Not empty";
}else{
echo "Empty";
}
echo $_Session['username5'];
?>
在checklogin.php上,它返回$ _Session [&#39; username5&#39;]的echo中的用户名,因此我知道会话已设置。
在Login_success上,我得到&#34;空&#34;来自echo,来自echo $ _Session [&#39; username5&#39;]的错误;就像它根本不再存在一样。
这两个页面都引用了session_start(),所以我不确定问题是什么。我对PHP很陌生,所以任何帮助都会受到赞赏!
答案 0 :(得分:0)
PHP区分大小写,快速修复会将所有会话实例都设置为CAPS。
像这样$ _SESSION [&#39; username5&#39;];