首页 > 编程语言 >PHP中session(报错Notice: Undefined index)无法获取值的原因(原因之一)与分析

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

时间:2022-11-01 22:01:14浏览次数:43  
标签:index Notice gameIndex echo session 报错 php SESSION out


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)无法获取值的原因(原因之一)与分析_解决方法_04

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


标签:index,Notice,gameIndex,echo,session,报错,php,SESSION,out
From: https://blog.51cto.com/u_15856491/5815040

相关文章