lukerodham Posted April 13, 2011 Share Posted April 13, 2011 hi guys me again. kinda stuck, im trying to turn my admin login script in to a user login with the admin side of things, so to keep things separate. for some reason the include function is not working after its checked, if the user is a admin or not. any ideas on why this would not work? have i done something completely wrong or just missing something. ive left the code below, if it helps aswell the login.php is a included file aswell to index.php. thanks in advance. login.php <?php $userback = $_SESSION['user']; $username = $_POST['username']; $password = md5($_POST['password']); $login = $_post['submit']; mysql_connect("db2700.oneandone.co.uk","dbo363845380","notgonnalie12"); mysql_select_db("db363845380") or die(mysql_error()); session_start(); if($_SERVER['QUERY_STRING'] == "logout") { unset($_SESSION['user']); header("Location: " . $_SERVER['PHP_SELF']); exit; } if(!isset($_SESSION['user'])){ if(!$submit){ echo"<div align='center'><b>Please login</b></div><br>"; echo " <html> <body> <div align='center'> <form method='post' action='".$_SERVER['REQUEST_URI']."'> <label>username: <input type='text' name='username' id='username'> <label>password: <input type='password' name='password' id='password'> </label> <label> <input type='submit' name='submit' id='submit' value='submit'> </label> </form> </div> </body> </html> "; } else { $rows = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."' AND password='".mysql_real_escape_string($password)."'")); if($rows>0){ while ($row = mysql_fetch_assoc($rows)){ $_SESSION['user']="$username"; $adminpass = $row['admin']; if($adminpass>=1){ include ("admin/index.php"); } else { echo "welcome $user1 you'll be directed in a few seconds.<br> if this doesn't happen please click here."; } } } else { if($rows<1){ echo "Sorry no user information found. Please make sure details are correct."; } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/233638-php-login/ Share on other sites More sharing options...
drisate Posted April 13, 2011 Share Posted April 13, 2011 Did not read all the code but first thing i noticed is that session_start(); needs to go befor the $userback = $_SESSION['user']; line Quote Link to comment https://forums.phpfreaks.com/topic/233638-php-login/#findComment-1201261 Share on other sites More sharing options...
lukerodham Posted April 13, 2011 Author Share Posted April 13, 2011 good spot thank you Quote Link to comment https://forums.phpfreaks.com/topic/233638-php-login/#findComment-1201267 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.