我正在开发一个项目,其中有一个包含登录链接的标题。我的项目header.php和header1.php上有两个标题。 header.php包含在index.php中,header1.php位于页面的其余部分。
当我访问包含header.php并登录的我的网站www.example.com时,它会告诉我我已登录但是当我移动到网站的下一页时,它不会显示我已登录,而且当我移动到主页(index.php)那里我也没有登录。
header.php: - 关于index.php
<?php
@session_start();
include_once('functions/config.php');
?>
// and some html code
header1.php: - 页面的其余部分
<?php
//ob_start();
@session_start();
include("$_SERVER[DOCUMENT_ROOT]/functions/config.php");
?>
// and some html code
vali.js(用于验证): -
$("#login_frm").validate({
rules: {
email: {
required: true,
email: true
},
pass: {
required: true,
minlength: 6
},
},
messages: {
pass: {
required: "Please provide a password",
minlength: "Your password must be at least 6 characters long"
},
email: "Please enter email adress"
},
submitHandler: function(form) {
$.post('http://www.example.com/logincheck.php', $("#login_frm").serialize(), function(data) {
if(data == '1') {
document.location='http://www.example.com/';
} else {
$('#login-error').html('Wrong Username or password');
}
});
}
});
logincheck.php(会话集): -
<?php
include("functions/config.php");
include("functions/encript.php");
ob_start();
session_start();
$email = $_POST['email'];
$pass= encode5t($_POST['pass']);
$sql = "SELECT * FROM members where email='$email' AND pass='$pass' AND member_status='1' ";
//echo $sql;
$row = mysql_query( $sql );
$count = mysql_num_rows( $row );
$result = mysql_fetch_assoc($row);
if($count == 1) {
$member_id = $result['member_id'];
$first_name = $result['first_name'];
$creditamount = $result['credit'];
$_SESSION['memid'] = $member_id;
$_SESSION['ufname'] = $first_name;
$_SESSION['uemail'] = $email;
$_SESSION['creditamount'] = $creditamount;
//echo "->".$_SESSION['memid'];
setcookie ("memid", $member_id, (time()+60*60*24*360));
setcookie ("login2", "true", (time()+60*60*24*360));
setcookie ("uname", $first_name, (time()+60*60*24*360));
setcookie ("uemail", $email, (time()+60*60*24*360));
echo '1';//header("location:index.php");
} else {
echo "Wrong Username Or Password";
}
?>
我不知道发生了什么事情这个问题第一次发生时,我第二次登录时它没有给我任何问题。提前谢谢。
答案 0 :(得分:3)
此问题可能由以下原因引起
标题和其他文件中的相同变量名称。该变量可以在标题
中使用$_SESSION['userid']
变量 $ userid 用于其他一些文件中。如果您发现此问题将清除我认为
答案 1 :(得分:0)
只需在每个页面的顶部使用session_start();
即可。