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
Share on other sites

Globals should be avoided where possible IMO. You need to pass $user in to the function where you call it as well, just declaring the function excepts an argument is not enough.

 

Maybe take a look at the man on functions. this is pretty straight forward stuff.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.