What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » php cookie help [solved]

Pages: (2): « First [ 1 ] 2 » Last »
php cookie help [solved]
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. Grin  php cookie help [solved]
I'm learning php now, and i'm trying to set cookie's, but it won't work :S

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.
[Image: 1-0.png]
             
03-07-2005 10:13 PM
Profile PM Web Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
38 / Male / Flag
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. :s "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! :spam:

03-07-2005 10:24 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: php cookie help
Ur right :P, but that won't fix it :-S, 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.
[Image: 1-0.png]
             
03-07-2005 10:28 PM
Profile PM Web Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
38 / Male / Flag
Joined: Aug 2004
Status: Away
RE: php cookie help
Cookie names are case-sensitive. You're calling naam, but you're setting Naam. Maybe correcting that will make it work. :o

Edit: :dodgy: I'm stupid today.

This post was edited on 03-07-2005 at 10:37 PM by L. Coyote.

Hack, hack, hack!
Finally became a Systems Analyst! :spam:

03-07-2005 10:36 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: php cookie help
I can see that my code was full of stupid bugs :-p, and i corrected all of them... BUT, it's still not working :-S

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.
[Image: 1-0.png]
             
03-07-2005 10:41 PM
Profile PM Web Find Quote Report
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
34 / Male / –
Joined: Jun 2004
RE: php cookie help
Does it give any errors? Or just plain not work
03-07-2005 10:45 PM
Profile PM Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
38 / Male / Flag
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! :spam:

03-07-2005 10:46 PM
Profile PM Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
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 :P, and after that i even tried submitting and then refreshing and after that even opening the page fresh-fresh :P

@Madman, the page loads ok, but it won't set the cookies :S
[Image: 1-0.png]
             
03-07-2005 10:50 PM
Profile PM Web Find Quote Report
Plik
Veteran Member
*****

Avatar

Posts: 1489
Reputation: 46
34 / Male / –
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
Profile PM Find Quote Report
L. Coyote
Senior Member
****

Avatar
Captain Obvious

Posts: 981
Reputation: 49
38 / Male / Flag
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! :spam:

03-07-2005 10:57 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On