[Cookies] Warning: Cannot modify header information - headers already sent by ...
Bonjour,
je realise un site e-commerce, je dois me servir des cookies mais j'ai ce message d'erreur quand je veux en creer un.
Citation:
Warning: Cannot modify header information - headers already sent by (output started at z:\site os commerce\easyphp1-8\www\liste deroulante\cookies.php:14) in z:\site os commerce\easyphp1-8\www\liste deroulante\cookies.php on line 15
voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
<?
///////////////////////////////////////////////////////////////////////////
//fichier qui permet la gestion des cookies
///////////////////////////////////////////////////////////////////////////
createCookie();
echo $_COOKIE['asocom'];
///////////////////////////////////////////////////////////////////////////
//fonction de creation d'un cookie avec son propre id
///////////////////////////////////////////////////////////////////////////
function createCookie(){
$expire = 60 * 60;
$id=random(10);
echo $id;
setcookie('asocom',$id,time()+$expire,'/asocom','.asocom.fr',0);
if(isset($_COOKIE['asocom'])){
echo 'cookie creer';
}
echo 'cookies non creer';
}
///////////////////////////////////////////////////////////////////////////
//fonction de creation de l'id du cookie
///////////////////////////////////////////////////////////////////////////
function random($car) {
$string = "";
$chaine = "abcdefghijklmnpqrstuvwxy";
srand((double)microtime()*1000000);
for($i=0; $i<$car; $i++) {
$string .= $chaine[rand()%strlen($chaine)];
}
return $string;
}
?> |