duanbeng1923 2014-03-27 04:23
浏览 16

PHP会话已设置但在不同页面中无法访问

I am using php session for accessing various values in different pages. Session is set but its not being accessible in different pages.

below is the code which i am using

in validation.php

session_start();
$_SESSION["username"] = $username;
$_SESSION["user_id"]  = $user_id;

in profile.php

session_start();
$username = $_SESSION["username"];
$user_id = $_SESSION["user_id"];

but both the variables return null value but when i am using below code in validation.php is shows session is set

echo "<pre>";
print_r($_SESSION);

This gives proper output in validation.php but its not being accessed at profile.php

i have tried with

error_reporting(E_ALL);

after

session_start(); 

but nothing is happening.

Please help me out this.

  • 写回答

1条回答 默认 最新

  • douwen0612 2014-03-27 08:56
    关注

    The session set in validation.php is accessible in profile.php as you have mentioned session_start(); before accessing. There is no issue in way of access. You have to redirect the page after setting session value to make it accessible by other pages. If you are accessing profile.php through redirection it will print and if through ajax then it will not print. Once after redirection it will work and print.

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)