imdead Posted April 25, 2008 Share Posted April 25, 2008 Hey Guys, 1 Last Problem I made this code (Practicly a re-write since i last showed you guys it) Anyway this is the Takelogin <?php ob_start(); session_start(); $conn = mysql_connect("localhost","root",""); $db = mysql_select_db("pete"); if(isset($_POST['submit'])) { $username = htmlspecialchars($_POST['username'], ENT_QUOTES); $password = htmlspecialchars($_POST['password'], ENT_QUOTES); $password = ($password); $username = addslashes($username); $password = addslashes($password); $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); if(mysql_num_rows($sql)>0) { session_register("username"); session_register("password"); $sessionid = session_name(); mysql_query("UPDATE users SET sessionid='$sessionid' WHERE username='$username' and password='$password' LIMIT 1"); ob_start(); exit(); ob_flush(); } if (mysql_num_rows($sql)>1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; } else { header("Location:login.php"); } } ob_flush(); ?> The problem is.. The code logs me in and everything although i get this error Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0 Also i dont think it is getting the row $userlevel becuase in the script where i want that displayed i have this if ($userlevel == '2'){ echo"<a style='color:#666; font-weight: normal;' href='/admin.php'>Admin Control Panel</a>"; } Although Nothing appears Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/ Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 You can't use session_register() if you don't have register globals turned on. ( which you shouldn't do ). Rather then session_register, use the global $_SESSION variable. Example <?php $_SESSION['password'] = $password; $_SESSION['username'] = $username; ?> http://us3.php.net/session_register Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/#findComment-527385 Share on other sites More sharing options...
imdead Posted April 25, 2008 Author Share Posted April 25, 2008 ok thanks, i've done this <?php ob_start(); session_start(); $conn = mysql_connect("localhost","root",""); $db = mysql_select_db("pete"); if(isset($_POST['submit'])) { $username = htmlspecialchars($_POST['username'], ENT_QUOTES); $password = htmlspecialchars($_POST['password'], ENT_QUOTES); $password = ($password); $username = addslashes($username); $password = addslashes($password); $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'"); if(mysql_num_rows($sql)>0) { $_SESSION['password'] = $password; $_SESSION['username'] = $username; $sessionid = session_name(); mysql_query("UPDATE users SET sessionid='$sessionid' WHERE username='$username' and password='$password' LIMIT 1"); ob_start(); exit(); ob_flush(); header("Location:index.php"); } if (mysql_num_rows($sql)>1){ $row = mysql_fetch_assoc($sql); $userlevel = $row['userlevel']; } else{ header("Location:login.php"); } } ob_flush(); ?> Which still seems to log me in fine and with no error although its not redirecting me to the index page anymore :S Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/#findComment-527394 Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 I forgot to mention that. The 'Location:' header requires a full URL including the 'http://' part. Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/#findComment-527398 Share on other sites More sharing options...
imdead Posted April 25, 2008 Author Share Posted April 25, 2008 Thats weird it works for the else statement? if i enter the password wrong it redirects me to login.php else{ header("Location:login.php"); } Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/#findComment-527402 Share on other sites More sharing options...
dptr1988 Posted April 25, 2008 Share Posted April 25, 2008 Ha!! I missed something. You have a call to exit(); 2 lines before the you try to send the 'index.php' location header. Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/#findComment-527406 Share on other sites More sharing options...
imdead Posted April 25, 2008 Author Share Posted April 25, 2008 ah dont worry i figured that part out header("Location:index.php"); exit(); ob_flush(); } header was in the wrong place EDIT: Lol you beat me Quote Link to comment https://forums.phpfreaks.com/topic/102947-solved-1-more-problem-last-one/#findComment-527408 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.