PHP Sessions

I see on my server that session files are being stored, but my variables won’t hold across pages. Any suggestions? I’m pretty new to this.
[php]
Page 1

session_start();

$test = ‘test’;

$_SESSION[‘user’] = $test;

Page 2

session_start();

$user = $_SESSION[‘user’];

echo $user;
[/php]

Does this problem occur on you local server or production server??? Because your code is absolutely fine there is nothing wrong with it, don’t know why this is happening???

What happens if you output the session rather than convert it to a variable?

Page2
[php]<?php
session_start();

echo $_SESSION[‘user’];

?>[/php]

The only thing I can think of is that maybe you didn’t wrap your code in PHP Tags?

Page1 should have

[php]

<?php session_start(); $test = 'test'; $_SESSION['user'] = $test; ?>

[/php]
Page2 Should have

[php]

<?php session_start(); $user = $_SESSION['user']; echo $user; ?>

[/php]

I found it was a problem with my PHP ini API on iPage host. They have a lot of settings messed up. I fixed the issue though. Thanks guys

Sponsor our Newsletter | Privacy Policy | Terms of Service