Home  >  Article  >  Backend Development  >  PHP method to save information to the current Session

PHP method to save information to the current Session

墨辰丷
墨辰丷Original
2018-06-12 14:52:241568browse

This article mainly introduces the method of php saving information to the current Session. The example analyzes the session usage skills in php. Friends in need can refer to it.

The example of this article tells the story of php saving information to the current session. Session method. The details are as follows:

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

<?php
 session_start();
 print("<html><b>");
 $_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[&#39;sitename&#39;]."\n";
 echo $_SESSION[&#39;MyChoice]."\n";
 print("</b></html>\n");
?>

The output result of the above code is as follows:

A value saved in the session named as MyLogin.
A value saved in the session named as MyColor.
W3M
red

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP uses phpmailer to send emails

##A brief introduction to the decorator pattern in PHP design patterns

A brief introduction to the adapter pattern in PHP design patterns

The above is the detailed content of PHP method to save information to the current Session. 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