0
点赞
收藏
分享

微信扫一扫

PHP中session(报错Notice: Undefined index)无法获取值的原因(原因之一)与分析

后来的六六 2022-11-01 阅读 176


PHP中的SESSION问题:

本文主题: 在页面之间传递session时,两页面文件不在同文件夹中而导致session无法传递,报错Notice: Undefined index…

此问题测试:

  • 文件结构:
    test文件夹:
    —gameIndex.php
    —out.php
    —php文件夹:in.php
    如图:
  • PHP中session(报错Notice: Undefined index)无法获取值的原因(原因之一)与分析_解决方法


  • PHP中session(报错Notice: Undefined index)无法获取值的原因(原因之一)与分析_文件结构_02

  • 文件内容:

gameIndex.php:

<?php
session_start();
echo $_SESSION['userid'];
?>

out.php:

<?php
session_start();
$_SESSION['userid'] = 4;
echo "<script>window.location.href = 'gameIndex.php'</script>";
?>

in.php:

<?php
session_start();
$_SESSION['userid'] = 4;
echo "<script>window.location.href = '../gameIndex.php'</script>";
?>

  • 测试:

1.浏览器访问:http://localhost:8081/dashboard/test/php/in.php

PHP中session(报错Notice: Undefined index)无法获取值的原因(原因之一)与分析_文件结构_03


2.浏览器访问:http://localhost:8081/dashboard/test/out.php

PHP中session(报错Notice: Undefined index)无法获取值的原因(原因之一)与分析_php_04

解决方法: 将两文件放到同一目录下。


举报

相关推荐

0 条评论