Forum Moderators: coopster

Message Too Old, No Replies

Cookies

Setting/Reading

         

MWpro

6:11 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



I have created a simple poll script using PHP and MySQL. I have decided to use cookies to prevent the users from voting after they have already voted. I found some tutorials on setting cookies with PHP, but they didn't really make sense and didn't go over how to read the cookie.

Is there anyone that can explain simply how to set and read a cookie with PHP? Thanks

jatar_k

6:23 pm on Jul 31, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What was it that you didn't understand?
or did you just not get it at all?

MWpro

6:50 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



How to read the cookies and use the value of it in a script.

jatar_k

7:08 pm on Jul 31, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It depends how you set them but the straight forward answer is

$_COOKIE superglobal array [ca2.php.net]

if we look at the setcookie function [ca2.php.net]

Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE or $HTTP_COOKIE_VARS arrays.

the example is
$value = 'something from somewhere';
setcookie ("TestCookie", $value);

then
echo $_COOKIE["TestCookie"];

the output would be
something from somewhere

you could also put the value into a var like so
$myvar = $_COOKIE["TestCookie"];

that make sense?

MWpro

8:32 pm on Jul 31, 2003 (gmt 0)

10+ Year Member



I see now; many thanks for explaining it : )