Home  >  Article  >  Backend Development  >  What should I do if php SESSION cannot be passed across pages?

What should I do if php SESSION cannot be passed across pages?

coldplay.xixi
coldplay.xixiOriginal
2020-09-30 14:52:113027browse

Methods to solve the problem that php SESSION cannot be passed across pages: 1. [session_start();] should be placed at the top of the page as much as possible; 2. [session: session_start();] must be manually turned on.

What should I do if php SESSION cannot be passed across pages?

Methods to solve the problem that php SESSION cannot be passed across pages:

1, session_start(); It should be placed at the top of the page as much as possible;

2. If session Autostart is not configured in php.ini, you must manually open session: session_start before each session. ();

3. Session is a super global variable in PHP, just like $_GET, $_POST, $_SERVER, so it must be capitalized when used:

$_SESSION['username']=$username;

4. Cross-page transfer example: a.php page transfers $_SESSION['username'] to b.php:

a.php:

b.php:

<?php
session_start();
echo $_SESSION[&#39;username&#39;];
?>

If you want to know more about programming learning, please pay attention to the php training column!

The above is the detailed content of What should I do if php SESSION cannot be passed across pages?. 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