Вопрос

I have this code in the login.php file :

 //save user data 
  $token=$user->getId().'_'.hash('sha256',$user->getUsername().microtime());
  $name='fsusr_'.$user->getUsername();

  //set session and server variables
  $_SESSION[$name]=$token;   //set session variable
  $_SERVER[$name]=$token;    //set server variable

and in the page_init.php , just after login process, I want to retrieve the server and session variables so that I can compare them , and decide what to do next:

I have this on line 8 :

 echo $_SERVER[$name];

In fact , the problem is that the other page sends me this error in this very line:

Undefined index: fsusr_smoootk in ... on line 8.

When I make an print_r($_SERVER) in login.php , I see the array containing the $_SERVER[$name] variable... But when doing the same in the other page, I see that it no more contains that variable.

I know that it did not save the server variable to the other page, But I don't know why?

thanks in advance

Это было полезно?

Решение

The $_SERVER variable is meant for server information. You should assign your own variables into $_SESSION.

http://us.php.net/manual/en/reserved.variables.server.php

Другие советы

try this $_SESSION['name'] = $token

you are saving data in session and echoing $_SERVER... nice man !

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top