Jump to content

[SOLVED] Login Error


Steve Angelis

Recommended Posts

<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

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

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.