php 中的 session 只能在同一页面上工作,但不能在同一网站的其他页面上工作 [英] session in php works only on the same page, but does not work on other pages in the same website

查看:43
本文介绍了php 中的 session 只能在同一页面上工作,但不能在同一网站的其他页面上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个简单的页面(test.php、test2.php).

I have two simple pages(test.php, test2.php).

test.php

<?php
session_start();
$_SESSION['username'] = "wria";
echo '<a href = "test2.php">click to another page</a> <br>';

if($_SESSION['username']) {
echo $_SESSION['username'];
}
?>

test2.php

<?php
session_start();
var_dump($_SESSION);
if($_SESSION['username']) {
echo $_SESSION['username'];
}
?>

在输出中,当我打开 test.php,刷新后

in the output, when I open test.php, after a refresh

但是当我去test2.php时,输出出现:

but when I go to test2.php, the output appears:

没有显示.

注意:此文件位于真实主机上,而非本地.

Note: this file is on real hosting not local.

推荐答案

您保存会话的路径不可用.您必须将其更改为可用位置.你可以在php.ini中更改

your path to save session is unavailable. You have to change it for an available place. You can change in php.ini

这篇关于php 中的 session 只能在同一页面上工作,但不能在同一网站的其他页面上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆