2013-01-02 57 views
2

在我的網站中,登錄功能在我們從索引頁面登錄時正常工作。但是當我從我的網站的索引頁面以外的其他頁面登錄時,它沒有登錄。登錄功能在網站的特定頁面中不起作用

http://domain.com/mysite/index.php

當用戶登錄此頁面,該功能工作正常,並登錄後顯示的頁面如下圖所示

After successful login

如果我們從我的網站其他頁面登錄它不能正常工作,它顯示頁面爲 http://mysite.com/samplefolder/detailpage.php?pollid=2&chid=2

After login also it shows sign in

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」); }} ?>

<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">&nbsp; 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

登錄編碼發佈 – Rithu

回答

0

確保您在每個文件的頂部調用session_start();。很可能您在某些頁面上錯過了該會話,因此會話不會繼續,因此看起來好像用戶已註銷。

+0

是的,頁面已經包含session_start();位於文件頂部 – Rithu

+0

任何其他解決此問題的方法 – Rithu

+0

@Rithu,發佈用於創建登錄鏈接的代碼以及任何相關的驗證代碼。 –