Home > Backend Development > PHP Tutorial > How to save information to the current Session in php_PHP Tutorial

How to save information to the current Session in php_PHP Tutorial

WBOY
Release: 2016-07-13 10:03:27
Original
963 people have browsed it

How to save information to the current Session in PHP

This article mainly introduces the method of saving information to the current Session in PHP. It analyzes the session usage skills in PHP with examples. What is needed Friends can refer to it

The example in this article describes how PHP saves information to the current Session. Share it with everyone for your reference. The details are as follows:

Session variables can be saved through $_SESSION in PHP. The following code simply demonstrates the usage of $_SESSION

?

1

2

3

4

5

6

7

8

9

10

11

session_start();

print("");

$_SESSION["sitename"] = "W3M";

print("A value saved in the session named as sitename.n");

$_SESSION["MyChoice"] = "red";

print("A value saved in the session named as MyChoice.n");

echo $_SESSION['sitename']."n";

echo $_SESSION['MyChoice]."n";

print("n");

?>

1 2

3

4

5

6

1

2

3

4

A value saved in the session named as MyLogin.

A value saved in the session named as MyColor.

W3M

red

7 8

9 10

11

session_start(); print(""); $_SESSION["sitename"] = "W3M"; print("A value saved in the session named as sitename.n"); $_SESSION["MyChoice"] = "red"; print("A value saved in the session named as MyChoice.n");
echo $_SESSION['sitename']."n";
echo $_SESSION['MyChoice]."n"; print("
n"); ?>
The output of the above code is as follows: ?
1 2 3 4 A value saved in the session named as MyLogin. A value saved in the session named as MyColor. W3M red
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/968668.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/968668.htmlTechArticleHow to save information to the current Session in php. This article mainly introduces the method of saving information to the current Session in php, with examples. Analyzed the session usage skills in php, friends in need can refer to it...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template