Steve Angelis Posted March 24, 2007 Share Posted March 24, 2007 <html><head> <title>:: Spartan Vanguard Central Command ::</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <link rel="stylesheet" type="text/css" href="../modules/style.css"> <?php // valid login credentials require('../inc/config.php'); $linkid = @mysql_connect("$db_host", "$db_uname", "$db_pass"); mysql_select_db("$db_name", $linkid); // grab current time $time=time(); $log_date = date("F j, Y"); // handle the logout event if ($logout == true) { setcookie ("user", md5($_POST[user]), $time-3200); setcookie ("pass", md5($_POST[pass]), $time-3200); header("Location: index.php"); } // handle validation event if ($_POST[user] && $_POST[pass]) { $user_data = mysql_fetch_array(mysql_query(" select id, adminname, adminpass, level from admin where adminname='$_POST[user]' and adminpass='$_POST[pass]' and level=4")); if ($user_data[id] > 0) { setcookie ("user", md5($user_data[user])); setcookie ("pass", md5($user_data[pass])); header("Location: index2.php"); } else { $login_error= true; } } // handle login event, both successful and erroneous, or show login screen if ($login_error == true) { ?> <div align="center"><img src="../jpg/banner.jpg"> <br> Your login Failed. Please go <a href=index.php>Back</a> and try it again.</div> <? } elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == md5($password)) { header('Location: index2.php'); } else { ?> <div align="center"><img src="../jpg/banner.jpg"> </div> <form action=index.php method=post> <table border="1" align=center cellpadding="0" cellspacing="0" bordercolor="#C7C7C7" style="font-family:arial; font-size:12; border:1 solid #000000;"> <tr> <td colspan=2 align=center>Administrative Login</td> </tr> <tr><td align=right>Username: </td><td><input type=text name=user size=15></td></tr> <tr><td align=right>Password: </td><td><input type=password name=pass size=15></td></tr> <tr><td align=center colspan=2><input type=submit value=Login></td></tr> </table> </form> <? } ?> This is my code for a login script. I know the connection to the database is right because if the login info is wrong it says it failed. Here is where it is located. http://www.svcommand.net/SCv7/admin. With that error, does anyone know where I am going wrong? Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/ Share on other sites More sharing options...
fert Posted March 24, 2007 Share Posted March 24, 2007 $linkid = @mysql_connect($db_host, $db_uname, $db_pass) or die(mysql_error()); mysql_select_db($db_name, $linkid) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-214408 Share on other sites More sharing options...
Steve Angelis Posted March 25, 2007 Author Share Posted March 25, 2007 I forgot that you cannot see the error without the password and username. Warning: Cannot modify header information - headers already sent by (output started at /home/eternalp/public_html/SCv7/admin/index.php:6) in /home/eternalp/public_html/SCv7/admin/index.php on line 28 Warning: Cannot modify header information - headers already sent by (output started at /home/eternalp/public_html/SCv7/admin/index.php:6) in /home/eternalp/public_html/SCv7/admin/index.php on line 29 Warning: Cannot modify header information - headers already sent by (output started at /home/eternalp/public_html/SCv7/admin/index.php:6) in /home/eternalp/public_html/SCv7/admin/index.php on line 30 Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-214559 Share on other sites More sharing options...
Steve Angelis Posted March 25, 2007 Author Share Posted March 25, 2007 I gave the above mentioned trick with headers but it had no affect what so ever. Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-214573 Share on other sites More sharing options...
sps Posted March 25, 2007 Share Posted March 25, 2007 setcookie() has to come before ANY page output so if the beginning of your script really begins as typed, you need to move - <html><head> <title>:: Spartan Vanguard Central Command ::</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <link rel="stylesheet" type="text/css" href="../modules/style.css"> to after the setcookie() calls. Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-214707 Share on other sites More sharing options...
JasonLewis Posted March 25, 2007 Share Posted March 25, 2007 or you can use output buffering, there is a thread stickied at the top of the PHP Help board about header errors. Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-214749 Share on other sites More sharing options...
Steve Angelis Posted March 26, 2007 Author Share Posted March 26, 2007 I did that, I even got rid of that code all together but it had no affect. Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-215196 Share on other sites More sharing options...
Steve Angelis Posted March 26, 2007 Author Share Posted March 26, 2007 Does anyone know what I should do? Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-215565 Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 <?php // valid login credentials require('../inc/config.php'); $linkid = @mysql_connect("$db_host", "$db_uname", "$db_pass"); mysql_select_db("$db_name", $linkid); // grab current time $time=time(); $log_date = date("F j, Y"); // handle the logout event if ($logout == true) { setcookie ("user", md5($_POST[user]), $time-3200); setcookie ("pass", md5($_POST[pass]), $time-3200); header("Location: index.php"); } // handle validation event if ($_POST[user] && $_POST[pass]) { $user_data = mysql_fetch_array(mysql_query(" select id, adminname, adminpass, level from admin where adminname='$_POST[user]' and adminpass='$_POST[pass]' and level=4")); if ($user_data[id] > 0) { setcookie ("user", md5($user_data[user])); setcookie ("pass", md5($user_data[pass])); header("Location: index2.php"); } else { $login_error= true; } } ?> <html><head> <title>:: Spartan Vanguard Central Command ::</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head> <link rel="stylesheet" type="text/css" href="../modules/style.css"> <?php // handle login event, both successful and erroneous, or show login screen if ($login_error == true) { ?> <div align="center"><img src="../jpg/banner.jpg"> <br> Your login Failed. Please go <a href=index.php>Back</a> and try it again.</div> <? } elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == md5($password)) { header('Location: index2.php'); } else { ?> <div align="center"><img src="../jpg/banner.jpg"> </div> <form action=index.php method=post> <table border="1" align=center cellpadding="0" cellspacing="0" bordercolor="#C7C7C7" style="font-family:arial; font-size:12; border:1 solid #000000;"> <tr> <td colspan=2 align=center>Administrative Login</td> </tr> <tr><td align=right>Username: </td><td><input type=text name=user size=15></td></tr> <tr><td align=right>Password: </td><td><input type=password name=pass size=15></td></tr> <tr><td align=center colspan=2><input type=submit value=Login></td></tr> </table> </form> <? } ?> Also make sure that there are NO spaces or whatsoever between the <?php and the top of the page as that will throw an error. Some text editors add that so try saving it in a different text editor see what happens. Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-215570 Share on other sites More sharing options...
Steve Angelis Posted March 28, 2007 Author Share Posted March 28, 2007 Ok that last one worked thanx so much. Link to comment https://forums.phpfreaks.com/topic/44157-solved-login-error/#findComment-216812 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.