devworkstation
devworkstation

Reputation: 147

setcookie PHP doesn't work in a right way

I have such situation: I do setcookie("bla",md5("bla"),time()+36000). After this I do see this cookie in the browser but If I will write print_r($_COOKIE) on the server - there will be not exist cookie with key "bla". Any ideas?

here is the listing:

  setcookie("login_cookie",md5($result['user_password']."solt"),time()+36000);
  setcookie("login_info",$result['user_id'],time()+36000);
  header("Location:{$_SERVER['HTTP_REFERER']}");
  exit();

Upvotes: 1

Views: 2524

Answers (2)

Rudi Visser
Rudi Visser

Reputation: 22019

Try the following (set the path argument to the root):

setcookie("login_cookie",md5($result['user_password']."solt"),time()+36000, '/');
setcookie("login_info",$result['user_id'],time()+36000, '/');

I have a feeling you're going out to a different directory in the redirect which is why it's not displayed, of course, I may be wrong.

Upvotes: 6

JAAulde
JAAulde

Reputation: 19560

$_COOKIE is one of the super globals which contain information passed in the HTTP request. You will only see it when a request has been made by a browser which already has the cookie, not directly after having called setcookie().

Also, in your code example, you appear to be trying to concat using the + operator:

$result['user_password']+"solt"

PHP uses the . operator for concat.

Upvotes: 2

Related Questions