Jump to content

Session


dalawh

Recommended Posts

The qualities you named are client side qualities! You can see them even in PHP sessions, just look at your cookies right now for this site, hint: PHPSESSID. As a site visitor these are all the variables that you can see. As the site author you can write code that will tell you anything else in the $_SESSION array. This stuff is kept on the server. You can't view that unless it's your server or unless you write code that displays that to visitors. As a site visitor the only thing you will see that makes a session cookie different than any other cookie is that it expires at end of session. That is one of the reasons why they are called session cookies.
I thought it was pretty obvious that I had access to the server. I been trying to say that in order for me to use session correctly, I must first understand it.
Link to comment
Share on other sites

Guest So Called

Dalawh did you miss my post where I said to session_start() then echo print_r($_SESSION) ??? Have you missed the part where I and others are trying to explain it to you? Did you miss my contact form example? Have you Googled "php session manual" ??? Just exactly what do you want?

Edited by So Called
Link to comment
Share on other sites

I don't believe you really understood the cookie properly. There aren't any "file variables" for the cookie. They are just settings, like how long you want the cookie to last and how many pages should have access to it. $_COOKIE[] is an associative array which has as many "variables" as you want it to. Each set_cookie() call adds a new "variable" to the $_COOKIE array. As for the session, there is nothing to it except one line of code:session_start() After starting the session, you can set any index of the $_SESSION[] array and it will remain accessible across all pages of your site. page1:

<?phpsession_start();$_SESSION['value'] = 5;?>

page2:

<?phpsession_start();if(isset($_SESSION['value'])) {    echo $_SESSION['value']; // Outputs "5"}?>

Link to comment
Share on other sites

Each $_SESSION has its own index ($_SESSION['indexName']) and each index has its own file variables. I am trying to figure out what file variables are listed under the indexes of $_SESSION. I hope this makes more sense.
you can have one session cookie at a time for particular browser. so that it can point only one session at a time. the session id refers to the file stored in server. file holds the data. data is stored as serialised data (you missed the boen's post) by default. php decode encode it and populate the $_SESSION super global array each time automaticaly. you dont have to do anything after it populates that array you can treat it like other array. http://php.net/serialize <= serialize manual to get idea how does your data will look after serialization
The index are defined in the php.ini.
php.ini does define configaration of php that how does it work. There is nothing called index which is defined in php.ini
file variable stored under all the indexes of the $_SESSION or does it have its own index?
where are you finding those terms? there is nothing called that called file variable.
I can view my cookies using chrome, but how can I view my sessions?
It by default saved in temp folder. you may find those there. but you dont need to see those files to work with session. php will do everything under the hood. you have tojust work with $_SESSION as you work with other array. to see data of it you can var_dump() or print_r() it. Edited by birbal
Link to comment
Share on other sites

The things you refer to as "file variables" are cookie options. Those are things like the domain the cookie is for, the path, whether Javascript can access it, the time it was created and expires, etc. Those are defined in the RFC that defines what cookies are. The important part about cookies are not that information, the important parts are the name and the value. The name becomes the index in the $_COOKIE array, and the value is whatever data the cookie contains. None of the other settings for the cookie really matter to this discussion. You can set those settings when you create a cookie using setcookie. The session cookie is like any other cookie. It has a name, a value, and the other normal cookie settings. You can set the settings for the session cookie inside php.ini or with this function: http://www.php.net/manual/en/function.session-set-cookie-params.php Notice that the name and value of the session cookie do not get changed with that function, only the properties of the session cookie. Don't confuse the session cookie with the session either, the session cookie is just one way (not the only way) for the client and server to use the session. The only purpose is to send the session ID to the server. By default, the name of the session cookie is PHPSESSID. If you want to change that, you use this function: http://www.php.net/manual/en/function.session-name.php The value of the session cookie is the session ID. PHP will auto-generate that. You can read or change it if you want to with this function: http://www.php.net/manual/en/function.session-id.php These are not options you need to change frequently. You decide what settings you want your session cookies to use, what name you want to use if you want to change it from the default, and you forget about the session cookie and go on with your life. When you are actually using the session to store and retrieve data you aren't doing anything with the session cookie, PHP handles all of that automatically so that the end result is that the $_SESSION array contains the data that you previously saved in the session.

Link to comment
Share on other sites

I don't believe you really understood the cookie properly. There aren't any "file variables" for the cookie. They are just settings, like how long you want the cookie to last and how many pages should have access to it. $_COOKIE[] is an associative array which has as many "variables" as you want it to. Each set_cookie() call adds a new "variable" to the $_COOKIE array. As for the session, there is nothing to it except one line of code:session_start() After starting the session, you can set any index of the $_SESSION[] array and it will remain accessible across all pages of your site. page1:
<?phpsession_start();$_SESSION['value'] = 5;?>

page2:

<?phpsession_start();if(isset($_SESSION['value'])) {	echo $_SESSION['value']; // Outputs "5"}?>

I understand this completely. I didn't know the term for it, so I called it file variables, but it seems it is called settings.
php.ini does define configaration of php that how does it work. There is nothing called index which is defined in php.ini
I know it is not called index. Things inside [] are the index. That is the general programming term.
where are you finding those terms? there is nothing called that called file variable.
I did not know what they were called, so I just called them file variables.
It by default saved in temp folder. you may find those there. but you dont need to see those files to work with session. php will do everything under the hood. you have tojust work with $_SESSION as you work with other array. to see data of it you can var_dump() or print_r() it.
Thanks for this. I will try it out.
The things you refer to as "file variables" are cookie options. Those are things like the domain the cookie is for, the path, whether Javascript can access it, the time it was created and expires, etc. Those are defined in the RFC that defines what cookies are. The important part about cookies are not that information, the important parts are the name and the value. The name becomes the index in the $_COOKIE array, and the value is whatever data the cookie contains. None of the other settings for the cookie really matter to this discussion. You can set those settings when you create a cookie using setcookie. The session cookie is like any other cookie. It has a name, a value, and the other normal cookie settings. You can set the settings for the session cookie inside php.ini or with this function: http://www.php.net/m...okie-params.php Notice that the name and value of the session cookie do not get changed with that function, only the properties of the session cookie. Don't confuse the session cookie with the session either, the session cookie is just one way (not the only way) for the client and server to use the session. The only purpose is to send the session ID to the server. By default, the name of the session cookie is PHPSESSID. If you want to change that, you use this function: http://www.php.net/m...ession-name.php The value of the session cookie is the session ID. PHP will auto-generate that. You can read or change it if you want to with this function: http://www.php.net/m....session-id.php These are not options you need to change frequently. You decide what settings you want your session cookies to use, what name you want to use if you want to change it from the default, and you forget about the session cookie and go on with your life. When you are actually using the session to store and retrieve data you aren't doing anything with the session cookie, PHP handles all of that automatically so that the end result is that the $_SESSION array contains the data that you previously saved in the session.
Now that makes perfect sense. Thanks for idiot proofing it :D
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...