我可以在任何文件中访问$ _SESSION吗?

我可以在任何文件中访问$ _SESSION吗?

问题描述:

i want to know if after i store a value in the $_SESSION, can i access it several times in different files?? for example i stored a value: $_SESSION['login']="Fred"

can i access that value in different files in different times??

for example: b.php

<?php
session_start();
$uname=$_SESSION['login'];
?>

c.php

<?php
session_start();
$uname=$_SESSION['login'];
?>

d.php

<?php
session_start();
$uname=$_SESSION['login'];
?>

is this possible??

我想知道在 $ _ SESSION code>中存储一个值后,我可以 在不同的文件中多次访问它? 例如我存储了一个值: $ _ SESSION ['login'] =“Fred” code> p>

我可以在不同的时间在不同的文件中访问该值吗?

例如: b.php p>

 &lt;?php 
session_start(); 
 $ uname = $ _ SESSION ['login  “]; 
&GT;吗?
 代码>  PRE> 
 
 

c.php p>

 &LT; PHP中
session_start()  ; \ N $ UNAME = $ _ SESSION [ '登录']; 
&GT;吗?
 代码>  PRE> 
 
 

d.php p>

  &lt;?php 
session_start(); 
 $ uname = $ _ SESSION ['login']; 
?&gt; 
  code>  pre> 
 
 

这是可能的 ?? p> div>

Yes, It is possible.

See PHP Session with details.

Note: PHP Session are meant to be that way, Unless you desrtoy it OR they are expired.

Yes. The $_SESSION variable will persist between PHP files, unless it expires or you destroy the session. In the most common server configurations this requires a cookie to save the session ID, so make sure those are enabled.

Yes your session will be available for each request from the same browser instance. if some where you are not getting it may be there session storage path is different for those files