What is the method for setting session in php?
In PHP, the method to set a session is to use the $_SESSION global variable to store and access session data. Here is an example code for setting a session:
// 开始一个新的session
session_start();
// 设置session变量
$_SESSION['username'] = 'John';
// 访问session变量
echo $_SESSION['username'];
In this example, the session_start() function is used to initiate a new session. Then, the $_SESSION array is utilized to set and access session variables. In this case, we have set a session variable named “username” with the value “John”. Finally, the echo statement is used to display the value of the session variable.