Reputation: 9803
Am using WAMP server for PHP development. I have created a cookie in my php but can't locate the cookie file being created. The php.ini
reads session.save_path=C:/wamp/tmp
and none of the files have been created today. The code is:
<?php
$mycookie="mycookie";
$emailAddr="[email protected]";
if (!isset($_COOKIE[$mycookie]))
{
if (!setcookie($mycookie, $emailAddr, 0))
{
echo "Cannot set cookie";
}
else
echo "Cookie is set";
}
?>
I get "Cookie is set" message but checking C:/wamp/tmp does not see any cookie file created today.
Upvotes: 1
Views: 14009
Reputation: 21449
Cookies are stored individually depending on a browser. they store them in their own folders.
what you are setting in your php.ini is the session path. which is the path for saving sessions $_SESSION
not cookies $_COOKIES
.
Upvotes: 7
Reputation: 655835
You seem to confuse cookie and session. Cookies are stored on the client side while sessions are stored on the server side. Although sessions often use a cookie, it is only used to store the session ID but not the actual data.
The actual storage location of cookies depends on the user agent. Most store them in files in the client’s file system. The session’s storage location is specified with session.save_path (except if you’re using a storage handler other than the default).
Besides that, setcookie
does always return true except for when the corresponding Set-Cookie header field could not be send due to the fact that the HTTP header has already been sent and hence cannot be modified anymore. The return value of setcookie
doesn’t say anything about whether the cookie was accepted or not.
Upvotes: 3