Javascript 登录后php会话数据丢失
用户登录后,数据被发布到包含以下代码的login_db.php文件中 它检查登录并将其存储到会话变量中。 根据登录类型的不同,self.location行将其带到不同的位置 在每个location1.php、location2.php和location3.php中,session_start都写在每个文件的第一行中Javascript 登录后php会话数据丢失,javascript,php,session-variables,Javascript,Php,Session Variables,用户登录后,数据被发布到包含以下代码的login_db.php文件中 它检查登录并将其存储到会话变量中。 根据登录类型的不同,self.location行将其带到不同的位置 在每个location1.php、location2.php和location3.php中,session_start都写在每个文件的第一行中 <?php extract($_POST); include_once 'login/utils/conn.php'; session_start(); if(isset($_
<?php
extract($_POST);
include_once 'login/utils/conn.php';
session_start();
if(isset($_POST['login']))
{
$name = $_POST['name'];
$password = $_POST['password'];
$sql = "SELECT ad_pk,ad_uname,ad_pwd,ad_type FROM adminlogin WHERE ad_uname ='$name' AND ad_pwd ='$password'";
$result = mysql_query($sql);
if($res = mysql_fetch_array($result))
{
//print_r($_POST);exit;
if ($res["ad_type"] == 'telecall')
{
$_SESSION["ad_uname"] = $res["ad_type"];
$_SESSION["adminid"] = $res["ad_pk"];
echo $dt=date("Y-m-d",time());
$pk=$res['ad_pk'];
$uk=$res['ad_uname'];
echo $sql_ins_log = "insert into login_info(user_id,user_name,login_date)values('$pk','$uk','$dt')";
$result_log = mysql_query($sql_ins_log);
echo "<script>self.location='location1.php';</script>";
}
else if ( $res["ad_type"] == 'admin')
{
$_SESSION["ad_uname"] = $res["ad_type"];
$_SESSION["adminid"] = $res["ad_pk"];
echo $dt=date("Y-m-d",time());
$pk=$res['ad_pk'];
$uk=$res['ad_uname'];
echo $sql_ins_log = "insert into login_info(user_id,user_name,login_date)values('$pk','$uk','$dt')";
$result_log = mysql_query($sql_ins_log);
echo "<script>self.location='location2.php';</script>";
}
else if ( $res["ad_type"] == 'bussuser')
{
$_SESSION["ad_uname"] = $res["ad_type"];
$_SESSION["adminid"] = $res["ad_pk"];
echo $dt=date("Y-m-d",time());
$pk=$res['ad_pk'];
$uk=$res['ad_uname'];
echo $sql_ins_log = "insert into login_info(user_id,user_name,login_date)values('$pk','$uk','$dt')";
$result_log = mysql_query($sql_ins_log);
echo "<script>self.location='location3.php';</script>";
}
else
{
echo "<script>alert('Incorrect username or password');self.location='login.php';</script>";
}
}
}
?>
会话启动()代码>必须是页面上的第一件事。看起来您的第一段代码并非如此,因此数据从未进入会话变量:您没有丢失会话数据,只是从未将其放在第一位。i shift session_start();login_db.php bt页面的第一行问题仍然存在将会话\u start切换到login_db.php开始后问题仍然存在
Please add session_start at the start of the page.
if still there is a problem with sessions please check phpinfo() for php settings.
Check session are enabled or not.
Below are session values for default settings :-
**session**
Session Support enabled
Registered save handlers files user sqlite
Registered serializer handlers php php_binary wddx
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path \xampp\tmp \xampp\tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0
Please add session_start at the start of the page.
if still there is a problem with sessions please check phpinfo() for php settings.
Check session are enabled or not.
Below are session values for default settings :-
**session**
Session Support enabled
Registered save handlers files user sqlite
Registered serializer handlers php php_binary wddx
Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path \xampp\tmp \xampp\tmp
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0 0