Home > Backend Development > PHP Problem > 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
Release: 2023-03-06 11:14:01
Original
3066 people have browsed it

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;
Copy after login

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

a.php:

Copy after login

b.php:

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

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!

Related labels:
php
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