简体   繁体   English

Session 在不同的页面中不起作用

[英]Session is not working in different page

I create a session and try to access it from another page under same domain and directory but it is not working.我创建了一个session并尝试从同一域和目录下的另一个页面访问它,但它不起作用。

<?php
   session_start();
   error_reporting(E_ALL);
   $_SESSION['abc'] = 'ajsdkla skjld ajsdlkja skld jasl';

   echo $_SESSION['abc'];

      ?>

Code for second page第二页代码

<?php
  error_reporting(E_ALL);
  session_start();
  echo '<h1> Session = '.$_SESSION['abc'].'</h1>';
    ?>

You can also check it on live here is a page one link您也可以在现场查看它是第一页链接
And here is a second page link这是第二页链接

When I try to access session on second page I found this error Notice: Undefined index: abc当我尝试在第二页访问session时,我发现了这个错误Notice: Undefined index: abc

I really wonder why this is happing can you please check it.我真的很想知道为什么会这样,请您检查一下。

Your live server (imube.com) responds with您的实时服务器 (imube.com) 响应

Set-Cookie:PHPSESSID=c1eb78a09f6cfe7830d6d445f95fa748; path=/; domain=.sadishop.com

That's a php configuration problem, since the cookie's domain don't match.这是一个 php 配置问题,因为 cookie 的域不匹配。 You can change that in runtime with session_set_cookie_params , example:您可以在运行时使用session_set_cookie_params更改它,例如:

session_set_cookie_params(0, '/', '.imube.com');

or you can change the session.cookie_domain parameter in your php.ini configuration file and leaves it empty.或者您可以更改 php.ini 配置文件中的session.cookie_domain参数并将其留空。

use the following code

biology.php生物学.php

<?php
   session_start();
   error_reporting(E_ALL);
   $_SESSION['abc'] = 'ajsdkla skjld ajsdlkja skld jasl';
   echo $_SESSION['abc'];
   header('Location: video.php');
?>

video.php视频.php

<?php
  error_reporting(E_ALL);
  session_start();
  echo '<h1> Session = '.$_SESSION['abc'].'</h1>';
?>

**Include some code in .htaccess file ** **在 .htaccess 文件中包含一些代码 **

RewriteEngine On
php_flag output_buffering on

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM