_absurd Posted April 30, 2007 Share Posted April 30, 2007 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 More sharing options...
MadTechie Posted April 30, 2007 Share Posted April 30, 2007 $user['auth'] wasn't passed to the function try function displayLogin($user) if that makes sense Link to comment https://forums.phpfreaks.com/topic/49380-solved-need-help-with-authorization/#findComment-241980 Share on other sites More sharing options...
_absurd Posted April 30, 2007 Author Share Posted April 30, 2007 Warning: Missing argument 1 for displayLogin() Notice: Undefined variable: user Link to comment https://forums.phpfreaks.com/topic/49380-solved-need-help-with-authorization/#findComment-241982 Share on other sites More sharing options...
ToonMariner Posted April 30, 2007 Share Posted April 30, 2007 or decalre $user as global within the function function displayLogin() { global $user; .... } Link to comment https://forums.phpfreaks.com/topic/49380-solved-need-help-with-authorization/#findComment-241983 Share on other sites More sharing options...
_absurd Posted April 30, 2007 Author Share Posted April 30, 2007 Ah, that worked ToonMariner. Thanks Link to comment https://forums.phpfreaks.com/topic/49380-solved-need-help-with-authorization/#findComment-241985 Share on other sites More sharing options...
trq Posted May 1, 2007 Share Posted May 1, 2007 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 https://forums.phpfreaks.com/topic/49380-solved-need-help-with-authorization/#findComment-241998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.