php cookie help [solved] |
Author: |
Message: |
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. php cookie help [solved]
I'm learning php now, and i'm trying to set cookie's, but it won't work
code: <form action="cookie.php" method="post">
<input type="text" name="naam" value="<?php $_COOKIE["naam"] ?>">
<input type="submit" value="Cookie Instellen" name="Submit">
<input type="button" onClick="<?php setcookie ("Naam","",time()-3600)?>" value="Cookie Wissen">
</form>
<?php
//cookies instellen
setcookie ("Naam", $_POST["naam"],time()+86400); /* onthoud naam voor 24 uur*/
setcookie ("Ipadres", $_SERVER["REMOTE_ADDR"], time()+86400); /*onthoud ip voor 24 uur */
//dingen naar de pagina printen
print "Als je binnen 24 uur op deze pagina terugkomt, weet het script je naam nog en je ipadres";
print "<br>" . "Naam: " . $_COOKIE["naam"] . "<br>" . "Ip-adres: " . $_COOKIE["Ipadres"];
?>
Does anyone know what i'm doing wrong?
This post was edited on 03-07-2005 at 11:33 PM by Ezra.
|
|
03-07-2005 10:13 PM |
|
|
L. Coyote
Senior Member
Captain Obvious
Posts: 981 Reputation: 49
39 / /
Joined: Aug 2004
Status: Away
|
RE: php cookie help
quote: Originally posted by Ezra
value="<?php $_COOKIE["naam"] ?>">
You are missing an "echo"
code: value="<?php echo $_COOKIE["naam"] ?>">
Edit: I now see the problem, I didn't look at it closely before.
You can't use JavaScript events with PHP. "onClick" is JavaScript/VBScript ONLY.
You can set the cookie via JavaScript, though. Also the page needs to be sent to the server in order for PHP to get the cookie.
This post was edited on 03-07-2005 at 10:27 PM by L. Coyote.
Hack, hack, hack!
Finally became a Systems Analyst!
|
|
03-07-2005 10:24 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: php cookie help
Ur right , but that won't fix it , cause i'm printing the cookies at the end too...
EDIT: I didn't know i couldn't mix javascript and php the way I did, but that button was just to delete the cookie. And now I removed the whole button it still doesn't work
This post was edited on 03-07-2005 at 10:31 PM by Ezra.
|
|
03-07-2005 10:28 PM |
|
|
L. Coyote
Senior Member
Captain Obvious
Posts: 981 Reputation: 49
39 / /
Joined: Aug 2004
Status: Away
|
|
03-07-2005 10:36 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: php cookie help
I can see that my code was full of stupid bugs , and i corrected all of them... BUT, it's still not working
My updated code
code: <form action="cookie.php" method="post">
<input type="text" name="naam" value="<?php echo $_COOKIE["naam"]?>">
<input type="submit" value="Cookie Instellen" name="Submit">
</form>
<?php
//cookies instellen
setcookie ("Naam", $_POST["naam"], time()+86400, "/", "", 0); /* onthoud naam voor 24 uur*/
setcookie ("Ipadres", $_SERVER["REMOTE_ADDR"], time()+86400, "/", "", 0); /*onthoud ip voor 24 uur */
//dingen naar de pagina printen
print "Als je binnen 24 uur op deze pagina terugkomt, weet het script je naam nog en je ipadres";
print "<br>" . "Naam: " . $_COOKIE["Naam"] . "<br>" . "Ip-adres: " . $_COOKIE["Ipadres"];
?>
This post was edited on 03-07-2005 at 10:47 PM by Ezra.
|
|
03-07-2005 10:41 PM |
|
|
Plik
Veteran Member
Posts: 1489 Reputation: 46
35 / / –
Joined: Jun 2004
|
RE: php cookie help
Does it give any errors? Or just plain not work
|
|
03-07-2005 10:45 PM |
|
|
L. Coyote
Senior Member
Captain Obvious
Posts: 981 Reputation: 49
39 / /
Joined: Aug 2004
Status: Away
|
RE: php cookie help
You're hitting submit or refreshing the page?
I too have a problem for not seeing obvious mistakes, so maybe that's why I can't point it out.
Hack, hack, hack!
Finally became a Systems Analyst!
|
|
03-07-2005 10:46 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
O.P. RE: php cookie help
try the updated code for urselve http://school.tsdme.nl/cookie.php
And yes I am hitting Submit , and after that i even tried submitting and then refreshing and after that even opening the page fresh-fresh
@Madman, the page loads ok, but it won't set the cookies
|
|
03-07-2005 10:50 PM |
|
|
Plik
Veteran Member
Posts: 1489 Reputation: 46
35 / / –
Joined: Jun 2004
|
RE: php cookie help
code: setcookie ("Naam", $_POST["naam"], time()+86400, "/", "", 0);
Thats ment to be a boolean not a integer
so
code: setcookie ("Naam", $_POST["naam"], time()+86400, "/", "", False or True);
would work (Note: chose between true or false)
Also you dont have to set all the parameters, unless you specifically need to controll the path and securty etc.. you could use
code: setcookie ("Naam", $_POST["naam"], time()+86400);
|
|
03-07-2005 10:55 PM |
|
|
L. Coyote
Senior Member
Captain Obvious
Posts: 981 Reputation: 49
39 / /
Joined: Aug 2004
Status: Away
|
RE: php cookie help
quote: Originally posted by Ezra
<?php echo $_COOKIE["naam"]?>
Should be Naam.
Hack, hack, hack!
Finally became a Systems Analyst!
|
|
03-07-2005 10:57 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|