session retrieving on page
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';
then cr开发者_StackOverfloweated a class user in which there is function userlogin as following:-
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['username'],$select_user['firstname'],$select_user['lastname']); is as following:-
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;
}
some time it work fine and some time not.
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");
}
}
}
?>
精彩评论