|
-
May 3rd, 2003, 10:02 PM
#1
Thread Starter
Ya ya Baby!!!Me is Back
Cookie problem
Hello,
I am new to PHP (few week) and I cannot write cookie corectly without having message error.
Here is the error :
Warning: Cannot add header information - headers already sent by (output started at c:\program files\easyphp\www\nowlogin.php:18) in c:\program files\easyphp\www\nowlogin.php on line 58
Here is the code of my .php:
PHP Code:
<html>
<head>
<title>[ P ] atriot</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK href="patriot.css" rel="stylesheet" type="text/Css">
</head>
<body>
<?php
require_once("header.php");
AfficherEntete();
?>
<?php
// db variables
// inserts variables accordingly
$host = "myip";
$user = "allo";
$pass = "bye";
$db = "nothere";
$table = "boo";
//Connection a la base de donnee
$link = mysql_connect ($host, $user, $pass)
or die("Impossible de se connecter : " . mysql_error());
//Selection de la base utilisee
mysql_select_db($db);
//Prend les parametres
$varId=$_POST['User_id'];
//Prend le numéro de de l'équipe
$sql = 'SELECT usagers_nom FROM usagers WHERE usagers_id = ' .$varId;
//Execute l'ordre sql
$result = mysql_query($sql)
or die ("NO USER FOUND");
$numRow = mysql_num_rows($result);
if ($numRow > 0)
{
//Prend la valeur de retour
$Nom = mysql_result($result,0);
echo($Nom. '(#' .$varId.') is logged');
//Enregistre le cookies!!!!!
setcookie ("patriot_user_id" , $varId , time()+600);
}
else
{
echo('Loggin failed');
}
mysql_free_result($result);
// closing the db link
mysql_close ($link);
?>
</body>
</html>
-
May 3rd, 2003, 10:04 PM
#2
Thread Starter
Ya ya Baby!!!Me is Back
I want to add the cookie only after verifying if the ID is correct in my database, I've read that it need to be before the HTML tag but I do not understand where to put it. Anyone can help me to modify my code, I've loss 2 days to try to put it work and it doesn't, I really need you!! 
Daok
-
May 6th, 2003, 08:50 AM
#3
Thread Starter
Ya ya Baby!!!Me is Back
-
May 6th, 2003, 10:49 AM
#4
Stuck in the 80s
Hey Daok,
The setcookie() function MUST be called before any output is sent to the browser.
Mean no HTML tags, echo statements, or blank spaces can come before you call the function.
-
May 6th, 2003, 10:51 AM
#5
Stuck in the 80s
Try doing something like this:
Code:
<?php
// db variables
// inserts variables accordingly
$host = "myip";
$user = "allo";
$pass = "bye";
$db = "nothere";
$table = "boo";
//Connection a la base de donnee
$link = mysql_connect ($host, $user, $pass)
or die("Impossible de se connecter : " . mysql_error());
//Selection de la base utilisee
mysql_select_db($db);
//Prend les parametres
$varId=$_POST['User_id'];
//Prend le numéro de de l'équipe
$sql = 'SELECT usagers_nom FROM usagers WHERE usagers_id = ' .$varId;
//Execute l'ordre sql
$result = mysql_query($sql)
or die ("NO USER FOUND");
$numRow = mysql_num_rows($result);
if ($numRow > 0)
{
//Prend la valeur de retour
$Nom = mysql_result($result,0);
//Enregistre le cookies!!!!!
setcookie ("patriot_user_id" , $varId , time()+600);
?>
<html>
<head>
<title>[ P ] atriot</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK href="patriot.css" rel="stylesheet" type="text/Css">
</head>
<body>
<?php
require_once("header.php");
AfficherEntete();
echo($Nom. '(#' .$varId.') is logged');
}
else
{
echo('Loggin failed');
}
mysql_free_result($result);
// closing the db link
mysql_close ($link);
?>
</body>
</html>
-
May 6th, 2003, 03:30 PM
#6
Thread Starter
Ya ya Baby!!!Me is Back
BIG BIG BIG THANKS to you man !
Thx Hobo!!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|