English 中文(简体)
在页面上检索会话
原标题:session retrieving on page
  • 时间:2011-09-29 09:45:40
  •  标签:
  • php
  • session

I have big problem related to login. actually some time it work fine but some time not working. I have setting.php in which session_start() is executing. this file is including in all file. another file is config.php where all variable is defined including session name

$siteConfig_session_name =  dhoombox ;

然后创建了一个类用户,其中有如下函数userlogin:-

function user_front_end_login($_POST,$checkout_page,$check){
    $errorMessage =   ;
    $userName = trim($_POST[ username ]);
    $password = md5(trim($_POST[ password ]));
$user_login = mysql_query("SELECT user_id, email_id,username, password , firstname, lastname, status FROM tbl_users WHERE  username=  ".$userName."  AND password =  ".$password."  ");
    $select_user = mysql_fetch_array($user_login);
if( mysql_num_rows($user_login)==1){
    $user_status = $select_user[ status ];
    //setAdminError( <span class="errormsg">Information has not been deleted!</span> );
        if( $user_status==1){

                 $this->setUserLoginSession($select_user[ user_id ], $select_user[ email_id ], $select_user[ username ],$select_user[ firstname ],$select_user[ lastname ]);


                    if($checkout_page==1){
                    siteRedirect("billing_info.php");
                    }
                    else{

                     print_r($_SESSION);
                     siteRedirect("index.php");
                    }

            }else{
                setAdminError( <span class="errormsg" style="color:#FF0000;">Sorry your account is not activated.</span> );     siteRedirect("login.php");
            }
    }else{
               setAdminError( <span class="errormsg" style="color:#FF0000;">Username or password mismatch</span> );
                    if($checkout_page==1){
                    siteRedirect("checkout.php");
                    }
                    else{                   
                    siteRedirect("login.php");
                    }       
            }
} 

$this->;setUserLoginSession($select_user[user_id]、$select_user[email_id]、$select_user[用户名]、$sectit_user[名字]、$Sectit_user[姓氏]);如下所示:-

function setUserLoginSession($uid, $email, $un, $fn,$ln) {
    global $siteConfig_session_name;

     $_SESSION[ user_id ]   = $uid;
     $_SESSION[ email_id ]  = $email;
     $_SESSION[ username ]  = $un;
     $_SESSION[ firstname ] = $fn;
     $_SESSION[ lastname ]  = $ln;
}

有时它工作良好,有时则不然。

问题回答

What problems are you having? Are you getting an error? session_start() has to be called in every page you want to use session variables in, you cannot start a session from an include.

<?php
session_start();
include your_include.php ;
user_front_end_login(post,checkout_page,check);
?>

<?php
session_start();
function user_front_end_login($_POST,$checkout_page,$check){
$errorMessage =   ;
$userName = trim($_POST[ username ]);
$password = md5(trim($_POST[ password ]));
$user_login = mysql_query("SELECT user_id, email_id,username, password , firstname, lastname, status FROM tbl_users WHERE  username=  ".$userName."  AND password =  ".$password."  ");
$select_user = mysql_fetch_array($user_login);
if( mysql_num_rows($user_login)==1){
$user_status = $select_user[ status ];
//setAdminError( <span class="errormsg">Information has not been deleted!</span> );
    if( $user_status==1){

             $this->setUserLoginSession($select_user[ user_id ], $select_user[ email_id ], $select_user[ username ],$select_user[ firstname ],$select_user[ lastname ]);


                if($checkout_page==1){
                siteRedirect("billing_info.php");
                }
                else{

                 print_r($_SESSION);
                 siteRedirect("index.php");
                }

        }else{
            setAdminError( <span class="errormsg" style="color:#FF0000;">Sorry your account is not activated.</span> );     siteRedirect("login.php");
        }
}else{
           setAdminError( <span class="errormsg" style="color:#FF0000;">Username or password mismatch</span> );
                if($checkout_page==1){
                siteRedirect("checkout.php");
                }
                else{                   
                siteRedirect("login.php");
                }       
        }
} 
?>




相关问题
why the session in iis automatically log out?

I used iis6, and when i called a function Directory.delete(), the all the session relate this website will be logged out. and i debugged the website, i found no exception. any one have ideas on this ? ...

Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

Can I get the size of a Session object in bytes in c#?

Is it possible to get the size(in bytes) of a Session object after storing something such as a datatable inside it? I want to get the size of a particular Session object, such as Session["table1"], ...

提供严格分类的出席会议物体

提供严格分类的与会机会的最佳方式是什么? 我正计划转而选择矩阵,这正在促使汇编者抱怨我的幻觉方案拟订方法......

PHP Session is not destroying after user logout

I m trying to create an authentication mechanism for my PHP Application and I m having difficulty destroying the session. I ve tried unsetting the authentication token which was previously set within ...

热门标签