Php $\我登录两次时仅会话设置
我有一个登录页面,将检查您的用户和密码。如果它是正确的,它应该引导你进入你的用户页面,但是我只有在输入用户名和密码两次后才能直接进入用户页面。它不设置Php $\我登录两次时仅会话设置,php,Php,我有一个登录页面,将检查您的用户和密码。如果它是正确的,它应该引导你进入你的用户页面,但是我只有在输入用户名和密码两次后才能直接进入用户页面。它不设置$\u会话['user']立即。为什么? 这是登录页面(它是从index.php调用的另一个文件调用的独立文件): 是,session_start()
$\u会话['user']代码>立即。为什么?
这是登录页面(它是从index.php调用的另一个文件调用的独立文件):
是,session_start()在保存诸如$\u SESSION['user']=$login代码>但我已尝试键入session_start();在login.php的开头仍然是一样的。您必须添加会话_start();到你想被重定向到的页面顶部,仍然没有结果。检查你的PHP日志中是否有“Headers ready sent”警告。如果您看到了这一点,那么您没有将会话\u start()
放在正确的位置。同意vnt,但不在登录脚本中调用会话\u start()。您无法将值“放入”您的$\u会话中。我刚刚检查过,没有类似的错误。我知道你的意思,但没有那样的错误。
<?php
header('content-type: text/html; charset: utf-8');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<div id="login-form">
<?php
$rop = $DB->query("SELECT * FROM admin_users");
// var_dump($rop);
if (isset($_POST['log-in'])) {
if (empty($_POST['login']) || empty($_POST['password'])) {
header("location:index.php?empty=Fill in all the fields");
} else {
$login = smart($_POST['login']);
$pass = smart($_POST['password']);
$select = $DB->query("SELECT * FROM `admin_users` WHERE `user` = '$login'");
$user = $select->num_rows;
if ($user == 1) {
$_SESSION['user'] = $login;
$x = $select->fetch_assoc();
$passh = md5(md5($pass));
$selects = $DB->query("SELECT * FROM `admin_users` WHERE user = '$login' AND pass = '$passh'");
$users = $selects->num_rows;
if ($users == 1) {
$_SESSION['pass'] = $passh;
header('Refresh: 0; url=' . $base_url . 'user');
} else {
header("location:index.php?Invalid=Wrong username and/or password!");
}
} else {
header("location:index.php?wrong=Wrong username and/or password!");
}
}
}
?>
<form method="POST" name="login-form" onsubmit="return validateLogin()">
<?php
if (@$_GET['empty'] == true) {
?>
<center style='color: red;'><?php echo $_GET['empty'];?></center><br>
<?php
} elseif (@$_GET['wrong'] == true) {
?>
<center style='color: red;'><?php echo $_GET['wrong'];?></center><br>
<?php
}
?>
<p id="email-login" class="email">Email<span class="required">*</span><img src="ico/ic-mail.png" align="right" class="ic-mail"></p>
<input id="email-login1" type="text" name="login">
<p id="pwd-login" class="pwd">Password<span class="required">*</span><img src="ico/ic-lock.png" align="right" class="ic-lock"></p>
<input id="pwd-login1" type="password" name="password">
<a id="forgot" href="#" class="forgot">Forgot?</a>
<button id="log-in" type="submit" name="log-in" class="loginb"><span style="cursor:pointer">login</span></button>
</form>
</div>
<?php
session_start();
include_once('../inc/config.php');
include('includes/inc.php');
include('includes/users.inc.php');
include('includes/users.inc-view.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-control" content="no-cache">
<link rel="icon" type="png" href="ico/logo.png" />
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200">
</head>
<body>
<?php
if (isset($_SESSION['user'])) {
?>
<div class="content">
<div id="main_nav">
<div class="menu_header">Hey, <?php echo $_SESSION['user'];?> [<a href="?logout">LOGOUT</a>]</div>
<div class="menu_header">User</div>
<a href="<?php echo $base_url;?>user/?users"><li>Add user details</li></a>
</div>
<?php
if (file_exists($pagex)) {
include($pagex);
} else {
echo "File: <i>" . $pagex . "</i> does not exist!";
}
?>
</div>
<?php
} else {
include('includes/goback.php');
}
?>
</body>
</html>
<?php
if(!isset($_SESSION['user'])){
header('Refresh: 0; url='.$base_url.'');
}else{
header('Refresh: 0; url='.$base_url.'user');
}