By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,847 Members | 2,296 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,847 IT Pros & Developers. It's quick & easy.

Session not holding a value

P: 4
Hello all,

I'm not familiar with PHP session, my question is if session save the values when I brows to another page.
It is possible to keep the session values when I go to other page (in the same domain)?

In one script, let's say a.php I'm doing:
[PHP]
session_start();
$_SESSION['fname'] = $row["fname"];
$_SESSION['lname'] = $row["lname"];
header("LOCATION: b.php")
[/PHP]

In b.php I'm doing:
[PHP]
print My name is: " .$_SESSION['fname']. " " . $_SESSION['lname'];
[/PHP]

I don't see the content of [PHP]$_SESSION['fname'] [/PHP] and [PHP]$_SESSION['lname'][/PHP]

Thank you,
Mar 16 '08 #1
Share this Question
Share on Google+
8 Replies


Markus
Expert 5K+
P: 6,050
on b.php you need to initialise the session.

On any page that uses sessions you need to use
[php]
session_start();
[/php]
Right before any other code.

Regards.
Mar 16 '08 #2

P: 4
Steel, I don't see the the session values...

what I missing??
Mar 16 '08 #3

Markus
Expert 5K+
P: 6,050
Steel, I don't see the the session values...

what I missing??
Well i dont know what your code is on b.php so i dont know.
Mar 16 '08 #4

P: 4
Lets say:

a.php contains:
[PHP]
<?php
session_start();
$_SESSION['username'] = 'shlomi';
$_SESSION['password'] = 'elbaz';
header("LOCATION: b.php");
?>
[/PHP]

b.php contains:
[PHP]
<?php
session_start();
print $_SESSION['username']. " " .$_SESSION['password'];
?>
[/PHP]

In the addressbar I see http://localhost/b.php but its show nothing
Mar 19 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
You must have made another error or typo because, when running your 2 scripts unchanged on my localhost, it runs fine, i.e. both values are printed.

Ronald
Mar 19 '08 #6

Markus
Expert 5K+
P: 6,050
You must have made another error or typo because, when running your 2 scripts unchanged on my localhost, it runs fine, i.e. both values are printed.

Ronald
As does mine.

Regards.
Mar 19 '08 #7

P: 82
Lets say:

a.php contains:
[PHP]
<?php
session_start();
$_SESSION['username'] = 'shlomi';
$_SESSION['password'] = 'elbaz';
header("LOCATION: b.php");
?>
[/PHP]

b.php contains:
[PHP]
<?php
session_start();
print $_SESSION['username']. " " .$_SESSION['password'];
?>
[/PHP]

In the addressbar I see http://localhost/b.php but its show nothing
Check session_save_path in your php.ini file. Make sure it has real path with write permissions.
Mar 19 '08 #8

P: 22
Check session_save_path in your php.ini file. Make sure it has real path with write permissions.
Also you can do a printout of phpinfo() and make sure session support is actually enabled. It'd be odd but it could happen.
Mar 19 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.