Reputation: 8207
I am setting a cookie in a PHP script which also has some html , the first line is setcookie function as required.
<?php
setcookie("user", "xyz", time()+3600);
?>
<html>
------ some html tags
</html>
In other PHP script where am trying to access , i get a blank value . $user=$_COOKIE["user"];
Can anyone tell me why is this happening ?
Upvotes: 0
Views: 103
Reputation: 27934
It is not a good practice to store sensitive information in cookies like this. Cookies may be edited by the user, so here he could set his "user" cookie to get being recognized as any user he wants. Its a better practice to use sessions instead. With sessions you can safely and easily bind any sensitive information to this specific user using the $_SESSION superglobal.
Upvotes: 1
Reputation: 186742
Your browser has cookies enabled, right?
What does var_dump( $_COOKIE['user'] ); print exactly? NULL, false?
Upvotes: 2