Home >Backend Development >PHP Problem >Why does php set session_id

Why does php set session_id

coldplay.xixi
coldplay.xixiOriginal
2021-02-20 17:07:141954browse

The reason why php sets session_id: [session_id()] gets or sets the Session ID, the syntax is [string session_id(string [id]);].

Why does php set session_id

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, DELL G3 computer. This method is suitable for all brands of computers.

php method to set session_id:

<strong>session_id()</strong>Get or set Session ID

Syntax:

string session_id(string [id]);

If there is no parameter id, it means that only the current Session code is obtained. Adding the parameter means that the Session code is set to the newly specified id. Input and return are both strings.

If the parameter ID is not set, it means to obtain the Session ID, otherwise it means to set the Session to the newly specified ID.

Note: IDs are all in string form.

session_id() example

Get Session ID

<?php
session_start(); 
echo session_id();
// 输出 urles147jbrq3u50b0l6f8hvf0
?>
设置Session会话ID
<?php
session_id("ilovemanongjc.com");
session_start(); 
    /* http://www.manongjc.com/article/1260.html */
echo session_id();
// 输出 ilovemanongjc.com
?>

Related free learning recommendations: Programming video

The above is the detailed content of Why does php set session_id. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn