Explanation of Usage of php session_decode Function

  • 2021-12-11 17:30:22
  • OfStack

How to use the php session_decode function?

Function: Decoding session data

Syntax:


bool session_decode ( string $data )

Parameters:

data, encoded data.

Description:

session_decode () decodes the serialized session data in the $data parameter and populates the $_SESSION super global variable with the decoded data.

The php session_decode () function uses example 1


<?php

session_start();

$_SESSION['login_ok'] = true;

$_SESSION['nome'] = 'sica';

$_SESSION['inteiro'] = 34;

echo session_encode();

?>

Output:


login_ok|b:1;nome|s:4:"sica";inteiro|i:34;

The php session_decode () function uses example 2


<?php

session_start();

$_SESSION['name'] = "php Chinese Web ";

$_SESSION['id'] = 1;

$_SESSION['pkey'] = 1;

echo session_encode();

?>

Output:


name|s:12:"php Chinese Web ";id|i:1;pkey|i:1;

Knowledge point supplement:

When you run an application, you open it, make some changes, and then close it. This is very much like a conversation. The computer knows who you are. It knows when you start the application and when it terminates. But on the Internet, there is a problem: The server doesn't know who you are and what you do, because the HTTP address can't be maintained.
PHP session solves this problem by storing user information on the server for later use (such as user name, purchase item, etc.). However, the session information is temporary and will be deleted after the user leaves the website. If you need to store information permanently, you can store the data in a database.

Copy the manual 1, and then try each one and write it out, so that you can consult it yourself. Who let me just learn it? Session has about 12 functions:

session_start: Initial session. session_destroy: End session. session_unset: Free session memory. session_name: Access the current session name. session_module_name: Access the current session module. session_save_path: Access the current session path. session_id: Access the current session code. session_register: Register a new variable. session_unregister: Delete registered variables. session_is_registered: Check whether the variable is registered. session_decode: Session data decoding. session_encode: Session data encoding.

Related articles: