Primer - ovde necete videti da se promenio $_COOKIE iako vec jeste:
Code:
<?
$prepost=$_POST['ime'];
$precookie=$_COOKIE['ime'];
if (isset($_POST['ime']) && ($_COOKIE['ime'] != $_POST['ime'])) {
setcookie ("ime", "", time()-3600,"/","",0);
setcookie ("ime", $_POST['ime'], time()+3600, "/","",0);
}
echo "Prepost=".$prepost.", Precookie=".$precookie.", Sad cookie=". $_COOKIE['ime'];
?>
<form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="ime">
<input type="submit" value="PROSLEDI">
</form>
<?
$prepost=$_POST['ime'];
$precookie=$_COOKIE['ime'];
if (isset($_POST['ime']) && ($_COOKIE['ime'] != $_POST['ime'])) {
setcookie ("ime", "", time()-3600,"/","",0);
setcookie ("ime", $_POST['ime'], time()+3600, "/","",0);
}
echo "Prepost=".$prepost.", Precookie=".$precookie.", Sad cookie=". $_COOKIE['ime'];
?>
<form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="ime">
<input type="submit" value="PROSLEDI">
</form>
U ovom drugom primeru cete videti da se ispisuje "pravi" cookie (ali se gubi _POST jer se ponovo ucitava stranica):
Code:
<?
$prepost=$_POST['ime'];
$precookie=$_COOKIE['ime'];
if (isset($_POST['ime']) && ($_COOKIE['ime'] != $_POST['ime'])) {
setcookie ("ime", "", time()-3600,"/","",0);
setcookie ("ime", $_POST['ime'], time()+3600, "/","",0);
header("Location: http://" . $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
exit;
}
echo "Prepost=".$prepost.", Precookie=".$precookie.", Sad cookie=". $_COOKIE['ime'];
?>
<form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="ime">
<input type="submit" value="PROSLEDI">
</form>
<?
$prepost=$_POST['ime'];
$precookie=$_COOKIE['ime'];
if (isset($_POST['ime']) && ($_COOKIE['ime'] != $_POST['ime'])) {
setcookie ("ime", "", time()-3600,"/","",0);
setcookie ("ime", $_POST['ime'], time()+3600, "/","",0);
header("Location: http://" . $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
exit;
}
echo "Prepost=".$prepost.", Precookie=".$precookie.", Sad cookie=". $_COOKIE['ime'];
?>
<form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="ime">
<input type="submit" value="PROSLEDI">
</form>
Eto. Mozda nekom zatreba.
P.S. Ima li drugi nacin OSIM ponovnog ucitavanja headera (cookie-a) za prikaz postavljenog cookie-a?
Kad sve ostalo zakaže, pročitaj uputstvo...