Jump to content

[SOLVED] Need help with authorization


_absurd

Recommended Posts

Ok, here is what I have so far in my config file:

 

if (empty ($_COOKIE['lhid']))
{
$user['auth'] = false;
$user[2] = 0;
}
else
{
$user = mysql_fetch_row (mysql_query ('SELECT `username`, `userid`, `level` FROM `users` WHERE MD5(CONCAT(`username`, `userpass`)) = \''.mysql_real_escape_string ($_COOKIE['lhid']).'\''));
if ($user)
{
	mysql_query ('UPDATE `users` SET `lastsec` = UNIX_TIMESTAMP(), `lastacip` = \''.$_SERVER['REMOTE_ADDR'].'\' WHERE `userid` = '.$user[1].' LIMIT 1');
	$user['auth'] = true;
}
else
{
	setcookie ('lh', null, 1);
	$user['auth'] = false;
	$user[2] = 0;
}
}

 

And here is where it is being used and receiving and error (line 3 below, line 30 in the error message):

"undefined variable: user"

 

function displayLogin()
{
	switch ($user['auth'])
	{
		case true:
			echo '<table class="small">
				<tr>
					<td class="head">Logged In</td>
				</tr>
				<tr>
					<td>Welcome, <b>'.$user[0].'</b>.<br /><br />
						<a href="#">[Contribute]</a><br />
						<a href="#">[Manage Account]</a><br />
						<a href="logout.php">[Log Out]</a></td>
				</tr>
			</table>';
			break;
		case false:
			echo '<table class="small">
				<tr>
					<td class="head">Login:</td>
				</tr>
				<tr>
					<td>Username:<br />
					<form name="login" method="post" action="login.php">
					<input type="text" name="username"><br />
					Password:<br />
					<input type="password" name="password"><br />
					<input type="submit" name="submit" value="Login"><input type="reset" name="reset">
					</form></td>
			</tr>
			<tr>
				<td><font size="1">Trouble? <a href="loginhelp.php">Login help.</a><br />
					No account? <a href="register.php">Register</a>.</font></td>
			</tr>
			</table>';
	}
}

 

But I defined it in the first bit of code, which is directly above the displayLogin function in the document. Can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/49380-solved-need-help-with-authorization/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.