06-25-2002, 06:46 AM
Please. could someone show me a few lines of code on:
How to create a session containing the word "Test"
How to delete a session
How to erase the data in the session
How to check if a session exists
How to read a session
06-25-2002, 09:14 AM
To create a session use the function :
To put some info in the session first declare a variable containing the info
i.e. $variable = "test";
Then register the variable to the session using
To erase the data in a session use the function session_unregister().
In my knowledge there is no specific function to check if a session is running what you could do is :session_start(); //start the session
$running = "1"; // create a variable saying the session is running
session_register("running"); // registering the variable to the session so that you can check on other pages if the session is running.
// Few lines later, when you want to check if the session exists : //
// do that
// do this
By "reading" a session I'll suppose you mean how to access the variables saved in a session.
First start the session ( session_start() ), you must do this on every page where you do session manipulations. Then use the variable in the session variables as normal variables.
i.e. echo $variable; // that will print "test" on the screen
To summarize it all :
// start the session
$running = 1;
// make a few variable
$variable1 = "blah";
$variable2 = "test";
// register them to the session
// check if the function is started
// print out the variables
echo $variable1 . "<br>" . $variable2;
echo "The session isn't working"
Hope that will help you.
For more information on sessions : http://www.php.net/manual/en/ref.session.php
06-25-2002, 09:23 AM
the seesions part in the PHP manual arent actually that clear. and another thing is if you are registering a variable with seesion_register() then there is no point putting session_start() because session_register calls it automatily (as it is said in the PHP manual). if you are checking session variables on each page just dump the checking code in a file and use request() or include() to have the code in the page you have just put request() or include() in, it will save you alot of time when it comes to going through your code
06-26-2002, 08:16 AM
It's true that session_register() implicitly starts the session but it's a better habbit to always use session_start(); It can always happen that you change the code to call a variable from the session before you register a variable and forget to add session_start().
06-27-2002, 12:31 PM
I like to use the session_destroy() method to clear and delete any and all session data (ie logout of a member area)
Just thought I'd add that as well.
06-29-2002, 06:38 AM
Using session_destroy(); does just that...However, it doesn't destroy your SID. I came back in and the same SID was assigned to me (?) yet the session data retained was different.
Umm...I asked for session help for two weeks here and never received a single reply. I had to figure it all out myself...Grrrrrrr :mad: