tags:

views:

110

answers:

4

How can you make a login cookie of the POST -data by PHP?

My code registration.php

global $login_cookie = $_POST['email'] . ',' . md5($_POST['password']);  
    // this does not work: Parse error: syntax error, unexpected '=', expecting ',' or ';'

setcookie("login_cookie", $login_cookie);            
      // this is empty because of the above

where the two pieces of POST data are not empty.

I run the following test-commands at index.php

 echo $login_cookie;       
 print_r($_COOKIE);

I get nothing.

The problem is in the first declaration of $login_cookie.

A: 

Get rid of global, it probably does not mean what you think it means.

deceze
+2  A: 

You are getting a syntax error because that line of code is invalid.

global $login_cookie = $_POST['email'] . ',' . md5($_POST['password']);

should be:

global $login_cookie;
$login_cookie = $_POST['email'] . ',' . md5($_POST['password']);

You should read up on the global keyword and be sure you're using it properly.

zombat
+1  A: 

Try

global $login_cookie;
$login_cookie = $_POST['email'] . ',' . md5($_POST['password']);
Alex L
+1  A: 

You probably can't assign a value for the variable when declaring it global. Do it separately:

global $login_cookie;  
$login_cookie = $_POST['email'] . ',' . md5($_POST['password']);
Zed