我正在开发一个项目,其中有一个包含登录链接的标题。我的项目 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";
}
?>
我不知道发生了什么,当我第二次登录时第一次出现这个问题,它不会给我任何问题。提前致谢。