I have found this tutorials in the internet when i run the registration page i dont have the problem whatsoever... but when i try to run this login.php there's an error saying....below..
Warning: Cannot send session cookie - headers already sent by (output started at c:\apache\htdocs\login\login.php:2) in c:\apache\htdocs\login\login.php on line 3
Warning: Cannot send session cache limiter - headers already sent (output started at c:\apache\htdocs\login\login.php:2) in c:\apache\htdocs\login\login.php on line 3
can you please help me how to debug this error. the code below....
for register.php
<form action='actions.php' method='post'>
<table cellpadding='2' cellspacing='0'>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
Username
</td>
<td>
<input type='text' name='f_username'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
Password
</td>
<td>
<input type='password' name='f_password'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
First name
</td>
<td>
<input type='text' name='f_fname'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
Last name
</td>
<td>
<input type='text' name='f_sname'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
E-mail adress
</td>
<td>
<input type='text' name='f_email'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
</td>
<td>
<input type='submit' name='f_save' value='Save'>
</td>
</tr>
</table>
</form>
for login.php
<?php
session_start();
echo"
<form action='actions.php' method='post'>
<table cellpadding='2' cellspacing='0'>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
Username
</td>
<td>
<input type='text' name='f_username'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
Password
</td>
<td>
<input type='password' name='f_password'>
</td>
</tr>
<tr>
<td style='width:100px;font-family:Verdana;font-weight:bold;font-size:12px;'>
</td>
<td>
<input type='submit' name='f_login' value='login'>
</td>
</tr>
</table>
</form>
<br>".$_SESSION['login_error'];
?>
and for the actions.php
<?php
session_start();// We need the session to keep the user logged in.
include('connect.php'); // We need to connection to execute queries
if($_POST['f_save'])
{
// First we check if all fields are not empty.
if(!empty($_POST['f_username'])
&& !empty($_POST['f_password'])
&& !empty($_POST['f_fname'])
&& !empty($_POST['f_sname'])
&& !empty($_POST['f_email']))
{
// If not empty we will execute this code.
// Here we will convert the password to an md5 encrypted code.
$password = md5($_POST['f_password']);
if(!mysql_query("INSERT INTO users
(username,password,firstname,lastname,email)
VALUES('".$_POST['f_username']."',
'".$password."',
'".$_POST['f_fname']."',
'".$_POST['f_sname']."',
'".$_POST['f_email']."') "))
{
echo "There was an error tryign to write the information to the database.";
}
else
{
echo $_POST['f_username']." has succesfully been added.";
}
}
else
{
// Not all information has been given.. you will
// automaticly return to the register page.
header("Location: ".$_SERVER['HTTP_REFERER']." ");
}
}
elseif($_POST['f_login'])
{
$get_user = mysql_query("SELECT * FROM users WHERE
username='".$_POST['f_username']."'
AND password='".md5($_POST['f_password'])."' ");
if(mysql_num_rows($get_user) > 0)// Means it's got result.
{
$_SESSION['s_username'] = $_POST['f_username'];
$_SESSION['s_password'] = md5($_POST['f_password']);
// The session variables have been made.
// You can send your user to the wanted page, in this case.. index.php.
// Please change the domain to your own.
header("Location: http://www.domain.com/index.php");
}
else
{
$_SESSION['login_error'] = "Your login information was incorrect.";
// Please change the domain to your own.
header("Location: http://www.domain.com/login.php");
}
}
?>
for index.php
<?php
session_start();// We need the session to keep the user logged in.
include('connect.php'); // We need to connection to execute queries
$get_user = mysql_query("SELECT * FROM users WHERE
username='".$_SESSION['s_username']."'
AND password='".$_SESSION['s_password']."' ");
if(mysql_num_rows($get_user) > 0)// Means it's got result.
{
$row_user = mysql_fetch_array($get_user);// provides you with user info
echo "
Welcome ".$row_user['firstname']." ".$row_users['lastname']."
<br><br>
Click <a href='logout.php'>here</a> to log out!";
// This will output a welcome message plus the link to the logout file.
}
else
{
// The user is not logged in.. so that means he has got to go to the login page.
// Please change the domain to your own.
header("Location: http://www.domain.com/login.php");
}
?>
for the logout.php
<?php
session_start();// You need to open the session.. if not it wont get destroyed.
/*session_destroy() is the function to destroy all current session values
instead of this you could also use the unset() function.
With unset you will have to specify what variables you want to be desroyed.
Example: unset($string,$string2);*/
session_destroy();
// Please change the domain into your own.
header("Location: http://www.domain.com/login.php");
?>