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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.