I can't seem to get session variables set by other scripts. PHP 7

Hi SP,

I’m having troubles getting session data set by other pages. Here is page1.php

<?
session_start();
$_SESSSION['test'] = 'some session text';
?>

and page2.php

<?
session_start();
print_r($_SESSION);
?>

and it’s output to the browser

Array()

The server is a local machine on the LAN running Ubuntu Server 16.04LTS, using the default LAMP stack installed through tasksel

Any tips in the right direction would be most helpful.

Ooh, also, it might be worth mentioning that I’m using Codiad over Firefox 48.0.2

That’s because $_SESSION is an array - try using var_dump instead of print_r and it will print the content of the array rather than telling you that it is an array.

1 Like
<?
session_start();
var_dump($_SESSION);
?>

output.

array(0) {}

Still not retrieving the session. And this appears to just be an issue if the session data is set on a different page (which is like the whole idea behind sessions right?)

I figured it out. There is 3 “s” characters in session. The whole issue was a typo! My old editor would highlight when I’m using PHP Environment super globals such as $_SESSION, $_GET etc. My new one doesn’t! Good to know.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.