php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19760 works. cleaned the sessiondata dir.
Submitted: 2002-10-04 15:34 UTC Modified: 2002-10-05 10:34 UTC
From: jonas at gauffin dot org Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.2.3 OS: WinXP
Private report: No CVE-ID: None
 [2002-10-04 15:34 UTC] jonas at gauffin dot org
Hello.

I got a 4-5 diffrent scripts that I use on a page to login on my site (db functions, general functions, login functions, html header/footer and loginpage).

When I login everything works fine except some session variables doesnt register.

I've used a die($_SESSION["url"]); right before the Header("startpage.php"); and the string prints correct. When I remove the die and put it on the first line in startpage.php it complains on "Notice: Undefined index: url in E:\projects\inetpub\cl4\user\startpage.php on line 3"

I've tried so reproduce the error on a more slim page without success.

These session variables are set ok:
	$_SESSION["email"] = $rs["email"];
	$_SESSION["userid"] = $rs["userid"];
	$_SESSION["nickname"] = $rs["nickname"];

	$_SESSION["gameid"]	= 1;
	$_SESSION["modid"]	= 1;

the variables in user_admin_flags_get() and user_teams_get() are not set.

login functions (user_login is called from the submit):

function user_login($email, $password)
{

	//Check if the activationcode match the saved one
	$sql = "SELECT userid FROM user_info WHERE email='".addslashes($email)."' AND password='".addslashes($password)."'";
	if (!$userid = db_execute_scalar($sql))
	{
		$GLOBALS["errormsg"] = "Incorrect email/password.";
		return false;
	}
	
	return user_login_userid($userid);
}

function user_login_userid($userid)
{

	$sql = "SELECT userid,email,status,nickname FROM user_info WHERE userid=$userid";
	if (!$resid = db_query($sql))
	{
		$GLOBALS["errormsg"] = "Failed to query the database ( $sql ).";
		return false;
	}

	//Fetch the row
	if (!$rs = db_fetch_row($resid))
	{
		$GLOBALS["errormsg"] = "Invalid/deleted userid.";
		return false;
	}
	
	if ($rs["status"] <= 0)
	{
		$GLOBALS["errormsg"] = "You're account are locked / You have not been validated.";
		return false;	
	}
	
	$_SESSION["email"] = $rs["email"];
	$_SESSION["userid"] = $rs["userid"];
	$_SESSION["nickname"] = $rs["nickname"];

	$_SESSION["gameid"]	= 1;
	$_SESSION["modid"]	= 1;
	
	user_admin_flags_get($userid);
	user_teams_get($userid);
	return true;
}


//fetch adminflags for the user
function user_admin_flags_get($userid)
{
	//Check if the activationcode match the saved one
	$sql = "SELECT * FROM user_admin WHERE userid=$userid";
	if (!$resid = db_query($sql))
	{
		$GLOBALS["errormsg"] = "Failed to query the database ( $sql ).";
		return false;
	}

	//set nada
	if (db_eof()) {
		$_SESSION[0][0] = 0;
		return;
	}
	
	//set all flags
	while (!$rs = db_fetch_row($resid))
	{
		$_SESSION[$rs["modid"]] = $rs["flags"];
	}
	
	//Set all nonexisting modflags to 0
	for ($a = 1; $a < MOD_COUNT; $a++)
	{
		if (!isset($_SESSION[$a]))
			$_SESSION[$a] = 0;
	}
	return true;
}

//fetch teams for the user
function user_teams_get($userid)
{
	//Check if the activationcode match the saved one
	$sql = "SELECT ti.teamid, ti.name, tu.status FROM team_user tu, team_info ti WHERE ti.teamid=tu.teamid AND tu.userid=$userid AND tu.status>0";
	if (!$resid = db_query($sql))
	{
		die($sql);
		$GLOBALS["errormsg"] = "Failed to query the database ( $sql ).";
		return false;
	}

	$_SESSION["url"] = '<a class="ff" href="../user/startpage.php">mypage</a> ';
	
	//Build a teamurl here
	//=======================================================
	if (db_eof()) {
		die("TEAM EOF");
		return true;
	}
	
	//Fetch all teams that the user is a member in.
	$a = 0;
	while ($rs = db_fetch_row($resid))
	{
		$_SESSION["url"] .= ' | <a class="ff" href="../team/myteam.php?teamid='.$rs["teamid"].'">'.$rs["name"].'</a> ';
		//$_SESSION["teamname"][$a] = $rs["name"];
		$_SESSION["teamstatus"][$rs["teamid"]] = $rs["status"];
		$a++;
	}
	$_SESSION["teamcount"] = $a;
	
	return true;
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-04 15:39 UTC] jonas at gauffin dot org
changed the summary.
 [2002-10-04 16:02 UTC] jonas at gauffin dot org
works..
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 15:01:31 2024 UTC