在我的网站中,从索引页面登录时,登录功能正常。但是当我们从我网站上的索引页面以外的其他页面登录时,它没有登录。
http://domain.com/mysite/index.php
从此页面登录时,功能正常,登录后显示页面如下所示
如果我们从我网站的其他页面登录,则它无法正常工作,并将页面显示为 的 http://mysite.com/samplefolder/detailpage.php?pollid=2&chid=2
Signin.php
<?php
include("jalert.php");
if (array_key_exists("login", $_GET)) {
$ oauth_provider = $ _GET ['oauth_provider']; if($ oauth_provider =='twitter'){ header(“Location:login-twitter.php”); } } ?&GT;
<script type="text/javascript">
$(document).ready(function() {
$("#new_user_session_ajax").submit(function(e){
e.preventDefault();
var email = $('#userid').val();
var password = $('#signin_password').val();
var remember = $('#user_session_remember_me').val();
$.ajax({
type: "POST",
url: "ajaxlogin.php",
data: "userid="+email+"&password1="+password+"&rememberme="+remember+""
}).done(function( msg ) {
if(msg)
{
$('#error').html(msg);
}
else
{
window.location.href="index.php";
}
});
});
});
</script>
<form accept-charset="UTF-8" action="" name="login" onsubmit="return checkreg();" class="no_scroll_animation validate no_bump ajax" id="new_user_session_ajax" method="post">
<input name="utf8" type="hidden" value="">
<input name="authenticity_token" type="hidden" value="yRcKhChgROcxunh7A7zRQVroShpYbO6e6PaAO4JHUtg=">
</div>
<input id="after_url" name="redirect_after_login" type="hidden" value="/">
<li class="remember_me clear">
<input name="user_session[remember_me]" type="hidden" value="0">
<input checked="checked" id="external_remember_me_popup" name="remember_me" type="checkbox" value="1">
<label for="external_remember_me_popup">Remember me</label>
<h5>Sign in with email</h5>
<li><input autocapitalize="off" class="validate validate_required validate_email placeholder" id="userid" name="userid" value="Email Address"
onfocus="if(this.value == 'Email Address') {this.value=''}" onblur="if(this.value == ''){this.value ='Email Address'}" title="email" type="email" value=""></li>
<li><input autocapitalize="off" class="validate validate_required placeholder" id="signin_password" name="password1" value="Password"
onfocus="if(this.value == 'Password') {this.value='';this.type='password'}" onblur="if(this.value == ''){this.value ='Password';this.type ='text'}" type="text" validate:message="Please enter your password" value=""></li><li class="last">
<input class="button" name="login" type="submit" value="Login" >
<div class="keepmeloggedin"><input name="rememberme" type="hidden" value="remember me"><input checked="checked" id="user_session_remember_me" value="remember me" name="rememberme" type="checkbox" value="1"> Remember me</div><div class="forgotPassword">
<a class="forget_pass" href="forgot_password.php" id="forgotPasswordLink" rel="nofollow">Forgot password?</a></div></li></ul></div></form>
Ajaxlogin.php
<?php
include("classes.php");
$jeob = new EF_Sql();
$email= $_POST['userid'];
$password= $_POST['password1'];
$papas=base64_encode($password);
$check = $_POST['rememberme'];
$tablename="user_record";
$select_qry = $jeob->SqlQuery("SELECT * FROM ".$jeob->dbprefix.$tablename." WHERE email ='$email' AND password ='$papas' AND active_link='1' ");
$kiss="SELECT * FROM ".$jeob->dbprefix.$tablename." WHERE email ='$email' AND password ='$papas'";
if($jeob->SqlRows($select_qry) == "0"){
echo "Invalid Username and Password";
} else {
if($check) {
setcookie("username", $email, time() + 3600); // Sets the cookie username
}
$getuser = $jeob->SqlFetch($select_qry);
$_SESSION['userid'] = $getuser['user_id'];
$_SESSION['oauth_provider'] = "normal";
$_SESSION['email'] = $getuser['email'];
}
?>
答案 0 :(得分:0)
确保在每个文件的顶部调用session_start();
。您可能在某些页面上遗漏了这些内容,因此会话不会延续,因此看起来好像用户已退出。