July 15, 2013

is 'user_id' a keyword in $_SESSION['user_id']?

Sattar_kuet.bd’s Question:

I have studied the following code:

$this->user_id = $_SESSION['user_id']=$user->id;

but $_SESSION['user_id'] this does not make any sense to me. ‘user_id’ inside $_SESSION[] is not any name attribute or input field name. So is user_id is a keyword reserved in php? if so what is the significance of this keyword?

$_SESSION are super global variables which store values in SESSION and can be accessed like arrays. So user_id is just an index of a value in Session not a reserved keyword.

On the following statement

$this->user_id = $_SESSION['user_id']=$user->id;

Value from $user -> id is stored in two places (1) $this -> user_id and (2) $_SESSION['user_id']

Just like user_id a session can hold any random indices. For example

$_SESSION['asdfsafasfsadfasd'] = 'aasfsafasfasfasfasf';

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!