Jump to content

[SOLVED] login script error...


phpSensei

Recommended Posts

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\learn\index.php:2) in C:\wamp\www\learn\func\checkUser_Login.php on line 48

 

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\learn\index.php:2) in C:\wamp\www\learn\func\checkUser_Login.php on line 45

 

Line 45:

setcookie("admin",$rec[0],time()-3600);
//Delete Existing Cookies

 

Line 48:

setcookie("admin",$rec[0],time()+3600);
//Assign New Cookies

 

CODE

<?php
function check_adminlogin(){
// Start Function // 

$username = trim($_POST['username']) ;
$password = trim($_POST['password']) ;
// Get All Values And Assign Them To Variables // 

if(isset($_COOKIE['admin'])){ // Check if the user is logged in or not

$message = die("You are already logged in as an admin"); // Show this mesasge if condition was TRUE

}
elseif(($username == "")||($password == "")){ // We check if the user has left any blank fields

$message = die("Please fill in a all the fields in the form"); 
}
else
{

$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
//Secure the script from any sql Injections

$username = strip_tags($username);
$password = strip_tags($password);
//Secure the script from XSS

$username = trim($username);
$password = trim($password);
//Remove all white spaces at the end of both fields


$rec=mysql_fetch_array(mysql_query("SELECT username, password FROM admin_table WHERE username = '$username' and password = '$password'"));// We make the admin table into an array //

$rec2=mysql_fetch_array(mysql_query("SELECT * FROM admin_table")); // Loop through all our database coloumns

if($rec2['username'] != $username){ // We check if the username exists in our database

$message  = die("No Such Username");

}
elseif(($rec[0]==$username)&&($rec[1]==$password)){ // We validate both username and password, to see if we have a match

setcookie("admin",$rec[0],time()-3600);
//Delete Existing Cookies

setcookie("admin",$rec[0],time()+3600);
//Assign New Cookies

echo "Welcome " . $username;
// Print Welcome Message
}
       else
            {
                 die("Login Faild");
         }
     }
// End Condition //
}
// End Function // 
?>

Link to comment
https://forums.phpfreaks.com/topic/67523-solved-login-script-error/
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.