In Log-in.php I have
$email=$_POST['email'];
$pass=$_POST['pass'];
$_SESSION['type'] = 'user';
$_SESSION['email'] = $email;
$_SESSION['pass']=$pass;
header('location:./connect.php');
我收到类似的错误undefined index email
对于其他用户登录,在另一边我可以在这里以管理员身份登录..
我有一个登录表单,可以查看这是什么类型的登录,并在会话中传递该类型连接.php它检查它是什么类型,然后继续它运行良好,但不幸的是出现错误无法再修改。
登录表单是用户、管理员和代理的一种表单,我可以以管理员身份登录,但无法以其他身份登录,它显示错误
if(empty($_SESSION))
{
session_regenerate_id();
session_start();
}
@mysql_connect('localhost','root','') or die("ERROR in SERVER");
@mysql_select_db('module') or die("ERROR IN DATABASE");
$_SESSION['start'] = time(); // taking now logged in time
if(!isset($_SESSION['expire'])){
$_SESSION['expire'] = $_SESSION['start'] + (60* 60) ; // ending a session in 30 seconds
}
$now = time(); // checking the time now when home page starts
if($now > $_SESSION['expire'])
{
session_destroy();
}
if(!empty($_SESSION['type']))
{
$email = $_SESSION['email'];
$pass = $_SESSION['pass'];
$type = $_SESSION['type'];
// admin login //
if($type == 'admin'){
$admin = mysql_query("SELECT * FROM `admin` WHERE `email` ='$email' ");
$res = mysql_fetch_array($admin);
if($email == "" || $pass == "" || $email != $res['email'] || $pass != $res['pass'])
{
header('location:./login/login.php');
}
}
// user login //
if($type == 'user')
{
$email = $_SESSION['email'];
$pass = $_SESSION['pass'];
$type = $_SESSION['type'];
$user = mysql_query("SELECT `id` FROM `users` WHERE `email`='$email' AND `status`='1'");
$useres = mysql_fetch_array($user);
// $trail = $useres['date'];
// $time = explode("/",$trail);
if($email != $useres['email'] || $pass != $useres['pass'])
{
echo mysql_error();
// header('location:./login/login.php');
}
else if($pass = $useres['pass']){
// echo '<script> location.replace("./user.php"); </script>';
}
}
// agent login //
if($type == 'agent')
{
$email = $_SESSION['email'];
$pass = $_SESSION['pass'];
$type = $_SESSION['type'];
$agent = mysql_query("SELECT `id` FROM `sale_agents` WHERE `email`='$email'");
$agentres = mysql_fetch_array($agent);
if($email != $agentres['email'] || $pass != $agentres['pass'])
{
header('location:./login/login.php');
}
else if($pass = $agentres['pass']){
// echo '<script> location.replace("./agent.php"); </script>';
}
}
}
else{
header('location:./login/login.php');
}
In one way I am getting error in other way page is also displaying email
what to do now?
分步会议
-
在一切之前定义会话,在此之前不应该有任何输出,无输出
<?php
session_start();
?>
-
在页面中设置您的会话,然后您就可以访问该页面,例如这是第1页.php
<?php
//This is page 1 and then we will use session that defined from this page:
session_start();
$_SESSION['email]='[email protected]';
?>
-
使用和获取会话2.php
<?php
//In this page I am going to use session:
session_start();
if($_SESSION['email']){
echo 'Your Email Is Here! :) ';
}
?>
NOTE: 评论没有输出。
也许可以回答你的问题:
我认为你没有设置会话,因此 PHP 不知道该会话多变的。
你的登录应该是这样的
<?php
session_start();
$email=$_POST['email'];
$pass=$_POST['pass'];
$_SESSION['type'] = 'user';
$_SESSION['email'] = $email;
$_SESSION['pass']=$pass;
header('location:./connect.php');
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)