<\/body>\n <\/html> <\/pre>\n\nNote:
\n<\/p>\n
(1) The session_start() function must be located before the tag, that is, the function must be called before any output. Often when writing a program, an extra space or carriage return is accidentally entered. In this case, An error will be reported. Special attention should be paid to this. (I have been tricked)
\n<\/p>\n
(2) The session_start() function will return TRUE regardless of whether the session is successfully created, so using any exception handling will not work.
\n<\/p>\n
(3) You can also enable the configuration instruction session.auto_start so that you do not have to execute this function, but in this case, a session will be started or continued when each php page is executed.
\n<\/p>\n
2. Store or read session <\/strong> The correct way to store and read session variables is to use PHP's S ESSION variable. SESSION variable. _SESSION is a global parameter provided by PHP and is specially used to store and read sessions. (Note that the key names of associative arrays are consistent with the naming rules of ordinary variables) When storing a session, you can assign it directly. $_SESSION['season'] = 'Autumn'; The above sets a session element with the key name \"season\" and its value is \"autumn\". When reading, it is just like calling a normal array element. The following two code snippets show how to store and read a session element. This is the session1.php file:
\n<\/p>\n
\n<\/p>\n
\n<\/p>\n
\n<\/p>\n
\n<\/p>\n
\n<\/p>\n
\n<\/p>\n\n\n <?php\n \/**\n * Created by PhpStorm.\n * User: yuxiu\n * Date: \/\/\n * Time: :\n *\/\n if(isset($_POST['submit'])){\n session_start(); \/\/開始建立一個會話\n $_SESSION['season'] = $_POST['season']; \/\/存儲會話數(shù)據(jù)\n header(\"Location: session.php\"); \/\/應特別注意header()里的格式問題\n }\n ?>\n 存儲會話<\/b>\n
\n 選擇需要設置的數(shù)據(jù):\n