Jump to content
Geplaatst:
comment_518859

Hallo allemaal, ik heb een probleem. Ik heb de volgende script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time(); 
setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);

if(isset($_COOKIE['lastVisit']))
$visit = $_COOKIE['lastVisit']; 
else
echo "You've got some stale cookies!";

echo "Your last visit was - ". $visit; 
?>
</body>
</html>

Het script werkt wel alleen krijg ik de volgende fout:

[b]Warning[/b]:  Cannot modify header information - headers already sent by (output started at /web-drive/gimyweb/homes/roy/counter.php:9) in [b]/web-drive/gimyweb/homes/roy/counter.php[/b] on line [b]10[/b]

Weet iemand waar dit door komt en hoe ik dit op kan lossen? Alvast bedankt. _O_

Featured Replies

Geplaatst:
comment_518863

Hey, Roy!

De functie setCookie() moet geplaatst worden vóórdat er enige output geparsed is. Dus voordat er tekst op het beeldscherm verschijnt, maar ook voordat je HTML tags gebruikt, of zelfs een spatie voor de <?php zet. Het zelfde geld ook voor de sessie gerelateerde functies en de header() functies. Kijk naar het volgende script:

   <?php
setCookie(x,x,x);
?>

Fout - Er staat een spatie (dat dus output is) voor <?php

Dus in jouw script zal dit wel werken:

<?php
$inTwoMonths = 60 * 60 * 24 * 60 + time();
  setcookie(lastVisit, date("G:i - m/d/y"), $inTwoMonths);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
//Calculate 60 days in the future
//seconds * minutes * hours * days + current time

if(isset($_COOKIE['lastVisit']))
$visit = $_COOKIE['lastVisit'];
else
echo "You've got some stale cookies!";

echo "Your last visit was - ". $visit;
?>
</body>
</html>

Succes!

Bewerkt: door ViceAgent

Een reactie plaatsen

Je kan nu een reactie plaatsen en pas achteraf registreren. Als je al lid bent, log eerst in om met je eigen account een reactie te plaatsen.

Gast
Op dit onderwerp reageren...

Recent actief 0

  • Er zijn hier geen geregistreerde gebruikers aanwezig.