Hi, i am doing an Authentication system, when i login, i have this error:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/intranet/ownlogin/index.php:18) in /var/www/html/intranet/ownlogin/functions.php on line 44
This error not always happen, occurs suddenly, i have no changed anything in the code. Why this error ??
Thx. for help
Ana Elisa MartÃnez
In the line
This is the login and the functions pages:
//Login.php
<?php
include_once ("functions.php");
if (!empty($user_name) and !empty($password)){
$respuesta = user_login($user_name,$password);
echo $respuesta;
}else {
echo "<form action='index.php' method='post'>";
echo "<p align=\"center\"><strong>Nombre de Usuario:<strong> </strong>";
echo "<INPUT TYPE='text' name=\"user_name\"><br>
<strong>Password: </strong><INPUT TYPE='password' name=\"password\">";
echo "<br><br><input type='submit' value='Entrada' name='entrar' size='25'>";
echo "<input type='reset' value='Cancelar' name='cancelar'></form>";
}
?>
//functions.php
<?php
mysql_connect("localhost","datatec","datatec1");
mysql_select_db("intranet");
$LOGGED_IN='false';
function user_login($user_name,$password) {
global $feedback,$LOGGED_IN;
if (!$user_name || !$password) {
$feedback .= ' ERROR - Missing user name or password ';
echo $feedback;
return false;
} else {
$user_name=strtolower($user_name);
$sql="SELECT * FROM usr WHERE user_name='$user_name' AND password='". md5($password) ."'";
$result=mysql_query($sql);
if (!$result || mysql_num_rows($result) < 1){
$feedback .= ' Usuario no existente o clave incorrecta <a href="index.php">Reintentar</a> ';
//echo $feedback;
return ($feedback);
} else {
$feedback .= ' SUCCESS - You Are Now Logged In ';
user_set_tokens($user_name);
header("Location: index.php?o=20");
echo $feedback;
return ($feedback);
}
}
}
function user_set_tokens($user_name_in) {
global $hidden_hash_var,$user_name,$id_hash;
if (!$user_name_in) {
$feedback .= ' ERROR - User Name Missing When Setting Tokens ';
return false;
}
$user_name=strtolower($user_name_in);
$id_hash= md5($user_name.$hidden_hash_var);
setcookie('user_name',$user_name,(time()+2592000),'/','',0);
setcookie('id_hash',$id_hash,(time()+2592000),'/','',0);
}