我需要创建登录/注册系统。用户可以提交他的详细信息及其工作正常,但我很难用他提交的用户名和密码在用户中创建会话/登录。当用户输入任何detalis时,我得到了信息:注意:会话已经启动,结果是任何人都可以访问受限子页面。它似乎是php代码无法检索记录的用户名和密码。谢谢你的提示。
<form form action=" <?php echo $self; ?>" method="POST">
<div>
<label for="user">Username:</label>
<input type="text" name="username" />
</div>
<div>
<label for="password">Password:</label>
<input type="password" name="password" />
</div>
<input type="submit" name="submit" value="submit" />
if(isset($_POST['submit'])){
if(!empty($_POST['username']) && !empty($_POST['password'])) {
$user=$_POST['username'];
$pass=$_POST['password'];
$file = fopen('filewriting.txt', 'r');
$clean = array();
while (!feof($file)) {
$clean = fgets($file);
}
fclose($file);
$clean['username'] = $user;
$clean['password'] = $pass;
if($user == $clean['username'] && $pass == $clean['password'] )
{
session_start();
$_SESSION['sess_user'] = $user;
}
} else {
echo 'Invalid username or password!';
}
} else {
echo 'All fields are required!!!';
}