dean7 Posted December 12, 2010 Share Posted December 12, 2010 Hi all, I've got a website, which used to work ... I have a login script which did log each user in fine, but now for some odd reason its not loggin them in, I've looked over the script quite a few times but carnt see why its not loggin then it as it use to. <?php session_start(); include_once"includes/config.php"; if (strip_tags($_GET['logout']) == "yes"){ session_destroy(); }elseif (isset($_SESSION['username'])){ header("Location: index2.php"); exit(); } if ($_POST['Submit'] && strip_tags($_POST['username']) && strip_tags($_POST['password'])){ $username = mysql_real_escape_string(addslashes(strip_tags($_POST['username']))); $password = md5(addslashes(strip_tags($_POST['password']))); $select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by rank desc"); $num = mysql_num_rows($select); $date = gmdate('Y-m-d h:i:s'); $ip = $REMOTE_ADDR; ///check INFO $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' LIMIT 1"); $login_check = mysql_num_rows($sql); $inf = mysql_fetch_object($sql); if ($login_check == "0"){ $message="<table width='30%' class='table' align='center' cellpadding='0' cellspacing='0' border='1'> <tr> <td class='header' align='center'>Error</td> </tr> <tr> <td align='center'>You could not be logged in.</td> </tr> <table><br />"; }elseif ($login_check != "0"){ if ($login_check > "0"){ if ($inf->status == "Banned"){ $encoded=md5(strtolower($username)); header("Location: banned.php?banned=$username&encoded=$encoded"); exit(); } session_register('username'); $_SESSION['username'] = $inf->username; $timestamp = time()+20; $get = mysql_query("SELECT * FROM users WHERE username='$username' LIMIT 1"); $got = mysql_fetch_object($get); $loginnumber = $got->loginnumber+1; mysql_query("UPDATE users SET online='$timestamp' WHERE username='$username'"); mysql_query("UPDATE users SET lastlogin='$date' WHERE username='$username'"); mysql_query("UPDATE users SET l_ip='$ip' WHERE username='$username'"); mysql_query("UPDATE users SET loginnumber='$loginnumber' WHERE username='$username'"); header("Location: index2.php"); } else { $message= "<table width='30%' class='table' align='center' cellpadding='0' cellspacing='0' border='1'> <tr> <td class='header' align='center'>Error</td> </tr> <tr> <td align='center'>You could not be logged in.</td> </tr> <table><br />"; }}} ?> <html> <head> <title>Login </title> <link href='style.css' rel='stylesheet' type='text/css'> </head> <body class='body'> <form action='' method='post' name='form1'> <?php echo ($message); ?> <table width='702' class='table' align='center' cellpadding='0' cellspacing='0' border='1'> <tr> <td class='header' align='center' colspan='2'>Welcome To Speed-Drive</td> </tr> <tr> <td align='center' colspan='2'><img src='images/banner.png'></td> </tr> <tr> <td class='header' align='center' colspan='2'>Speed-drive Login</td> </tr> <tr> <td width='50%' align='right'>Username:</td><td width='50%' align='left'><input name="username" class='input' type="text" maxlength="15" id="username"></td> </tr> <tr> <td width='50%' align='right'>Password:</td><td width='50%' align='left'><input name="password" class='input' type="password" maxlength="30" id="password"></td> </tr> <tr> <td colspan='2' align='center' class='omg'><input type="submit" class='button' name="Submit" value="Submit"></td> </tr> <tr> <td class='header' align='center' colspan='2'>Help</td> </tr> <tr> <td align='center' colspan='2'><a href='register.php'>Register</a> .|. <a href='lost.php'>Lost Password</a> .|. <a href='tos.php'>TOS</a></td> </tr> <tr> <td align='center' colspan='2'><br /><font color='pink'><strong><h3>This website is currently <u></font><font color='red'>closed</font><font color='pink'></u>!<br /><br />You will <u></font><font color='red'>Not</font><font color='pink'></u> be able to Register untill the website is completed.<br /><br /></font></h3> Thank you for understanding.</strong></td> </tr> </table> </form> </body> </html> Is there a small error in the script or is the Script fine? Thanks for all the help given. Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/ Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 is there really a blank line before the open PHP tag <?php. I suspect not, but if there is that would probably break session_start() and you should have gotten a header error and session would be broken, too. Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146232 Share on other sites More sharing options...
dean7 Posted December 12, 2010 Author Share Posted December 12, 2010 is there really a blank line before the open PHP tag <?php. I suspect not, but if there is that would probably break session_start() and you should have gotten a header error and session would be broken, too. No sorry there isnt a line at the start of <?php just how I copyed my code wrong. Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146238 Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 that's what i figured. my next step would be to start placing echo's throughout the processing to see what's going on. Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146246 Share on other sites More sharing options...
dean7 Posted December 12, 2010 Author Share Posted December 12, 2010 May sound dumb, but what could you echo out on the Login Script? But on the other hand, I've found a few errors: Notice: Undefined index: logout in /home/www/****-****.comindex.php on line 8 Notice: Undefined index: Submit in /home/www/****_****.com/index.php on line 15 Notice: Undefined variable: message in /home/www/****-****.com/index.php on line 97 Also, I've noticed its only happend since I've edited the "index2.php" script it goes to once the login is right. But I carnt see if there is something wrong with that either as thats just a basic script: index2.php <?php session_start(); include_once "includes/config.php"; include_once "includes/functions.php"; logincheck(); ?> <link href='style.css' rel='stylesheet' type='text/css'> <head> <title>Logged In!</title> </head> <link rel='shortcut icon' href='favicon.ico' /> <frameset rows='116,*' cols='*' frameborder='no' border='0' framespacing='0'> <frameset rows='*,25' cols='*' framespacing='0' frameborder='no' border='0'> <frame src='banner.php' name='topFrame' scrolling='No' noresize='noresize' id='topFrame' title='topFrame' /> <frame src='stats.php' name='Stats' scrolling='No' noresize='noresize' id='Stats' title='Stats' /> </frameset> <frameset rows='*' cols='130,*' framespacing='0' frameborder='no' border='0'> <frame src='menu.php' name='leftFrame' noresize='noresize' id='leftFrame' title='leftFrame' /> <frame src='news.php' name='mainFrame' id='mainFrame' title='mainFrame' /> </frameset> </frameset> <noframes></noframes> Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146260 Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 by echoing, i mean follow processing and check values. for instance: echo "Before submit check <br />"; if ($_POST['Submit'] && strip_tags($_POST['username']) && strip_tags($_POST['password'])){ echo "In submit check <br />"; // etc., etc., etc. It's a heck of a lot easier to have PHP echo what it's doing than trying to look at the code and imagine following the logic. Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146267 Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 Notice: Undefined index: logout in /home/www/****-****.comindex.php on line 8 This means you are referencing $_GET['logout'] without it existing. you should check whether it's set before checking it's value. if (isset($_GET['logout']) && strip_tags($_GET['logout']) == "yes") { Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146268 Share on other sites More sharing options...
OOP Posted December 12, 2010 Share Posted December 12, 2010 What do you get when you try to login? any errors? Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146270 Share on other sites More sharing options...
dean7 Posted December 12, 2010 Author Share Posted December 12, 2010 Weridly just leaving it some time while looking though the Script its accually logging me in fine for the time being :S. Link to comment https://forums.phpfreaks.com/topic/221406-login-script-error/#findComment-1146272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.