Session_start (): enable the session mechanism. call session_register (): register the session variable session_unregister () at the beginning of the program file that requires the session ():
Session_start (): Enables the session mechanism and calls it at the very beginning of the program file that requires the session.
Session_register (): registers the session variable.
Session_unregister (): deletes session variables one by one)
Session_is_registered (): determines whether the session variable is registered.
Session_distroy (): destroys all session variables (destroys all session variables)
Initialize session, instance 1:
- Session_start ();
- // Delete all session variable values
- $ _ Session = array ();
- If (isset ($ _ cookie [session_name ()])
- {
- Setcookie (session_name (), '', time ()-42000 ,'/');
- }
- // Cancel all sessions
- Session_destroy ();
Instance 2
- Session_start (); // initialize the session
- $ A = 5; // define the variable
- Session_register ('A'); // register the session
- Session_decode (" "); // Decrypt the string
- Print (session_is_registered ('A ')? $ _ Session [a]: 'Not registered'); // determines whether the variable is registered.
Instance 3
- /* Initialize the session */
- Session_start ();
- $ _ Session ['login _ OK '] = true; // defines the session value.
- $ _ Session ['nome'] = 'sica '; // defines the session value.
- $ _ Session ['inteiro '] = 34; // defines the session value.
- $ Result = session_encode (); // encrypt the session value
- Echo $ result; // output result
- Session_destroy (); // deregister all session values
Instance 4
- Session_start (); // initialize the session
- $ _ Session ['name'] = "yoursession"; // register a session variable
- If (! Isset ($ _ session ['initiation']) // if a value is not set
- {
- Session_regenerate_id (); // Obtain the current session id
- $ _ Session ['initiation'] = true; // The set value is true.
- }
- Session_destroy (); // cancel the session
Instance 5
- Session_start (); // initialize the session
- $ _ Session ['name'] = "yoursession"; // register a session variable
- If (session_is_registered (name) // judge
- {
- Echo "the specified variable has been registered as a session
"; // Output Content
- }
- Else
- {
- Echo "the specified variable is not registered as a session
"; // Output the corresponding result
- }
- Session_destroy (); // cancel the session