spdwrench Posted August 27, 2007 Share Posted August 27, 2007 when I turned errors on in one of my php pages I got this error.. but the page still works fine.. I never had to declare a variable in php... why is it telling me I have an undefined? I thought they were defined when you define them? just wierd Paul Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/ Share on other sites More sharing options...
Wuhtzu Posted August 27, 2007 Share Posted August 27, 2007 Some code please? Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/#findComment-335547 Share on other sites More sharing options...
Neptunus Maris Posted August 27, 2007 Share Posted August 27, 2007 Whatcha talkin about... hos? yes... show a code snippet Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/#findComment-335555 Share on other sites More sharing options...
spdwrench Posted August 27, 2007 Author Share Posted August 27, 2007 <?php $nauth=0; $nauth=$sAuth; ?> undefined line 3 $sAuth is a variable that comes from another part of the site into the phpbb system it works fine just wondering why says undefined? I thought it did not matter in php? Paul Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/#findComment-335556 Share on other sites More sharing options...
spdwrench Posted August 27, 2007 Author Share Posted August 27, 2007 I dont know alot about sessions all I know is that sAuth allows me to determine which member is logged in to my system it reflects the member ID # on my site Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/#findComment-335559 Share on other sites More sharing options...
Neptunus Maris Posted August 27, 2007 Share Posted August 27, 2007 At login set a session or cookie in this case you mentioned cookies setcookie("nameofcookie", "valueofcookie", time()+3600, "/", "yoursite.com", 1); name of the cookie maybe be "users" value could be under a field like "auth_lvl" ranging from 1-3 1 being a super admin and then down the line do this in secure areas if (!isset($_COOKIE['users'])) { header(); // send them somewhere else exit; } then to check auth_lvl if ($_COOKIE['users'] != 1) { die("Unauthorized"); } but $_SESSIONS are bettter to use Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/#findComment-335568 Share on other sites More sharing options...
Wuhtzu Posted August 27, 2007 Share Posted August 27, 2007 As you said earlier, the page still works - so in that sense it does not matter. All it tells you is that you have used some bad coding practice... take this example: script.php <?php error_reporting(E_ALL); $id = $_GET['id']; echo $id; ?> If I call the script.php without the ID get argument PHP will throw a notice saying that I have an undefined index... all this means is that $_GET['id'] does not exist even though I'm using it. The end result is of course that $id will hold the value '' and nothing will be printed to the screen... fine. But it would be good practice to test for the existence of $_GET['id'] before using it. if($_GET['id']) { $id = $_GET['id']; } I know it's not the exact same thing, but it a similar case. If you wanna know exactly why it says undefined (which is only a part of the error - what is the rest?) you will have to post the whole error message Quote Link to comment https://forums.phpfreaks.com/topic/66924-undefined-variable-message/#findComment-335574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.