Patrick Narcelles
Patrick Narcelles

Reputation: 167

can i access $_SESSION in any file?

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??

Upvotes: 1

Views: 120

Answers (3)

Rupesh Patel
Rupesh Patel

Reputation: 3065

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

Upvotes: 0

Leon Lucardie
Leon Lucardie

Reputation: 9730

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.

Upvotes: 1

Rab
Rab

Reputation: 35572

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.

Upvotes: 3

Related Questions