PDA

View Full Version : Sessions + php problem (i think)



mikejg
12th July 2006, 10:43 AM
The php all renders just fine and dandy, but I do have an issue. Currently running FC 5, MySQL is 5 something or other, as is the php install too.

When "Logging in" on the website I am creating, I set some session variables:

$_SESSION['first_name'] = $row["fname"];

$_SESSION['last_name'] = $row["lname"];

$_SESSION['email_address'] = $row["email"];

$_SESSION['user_id'] = $row["userId"];

$_SESSION['access_level'] = $row["access_level"];

The problem is, when re-directing back to the main page (index.php), the page checks to see if the

$_SESSION['access_level'] > 1
If it is, the page displays with a side menu which has various items dependant upon their access level. Right now, though, there is no menu - which relates to if no session (or less than 0) for access level is set, then it's just the main page only.

So I am assuming that somewhere I have not got it set up for sessions correctly - but I am having a bit of difficulty trying to find exactly where I should be checking. I disabled SElinux (or whatever its called), and google searches for sessions + php + fedora brings up lots of extraneous rubbish (about meetings/conventions) instead of what I am after.

Any suggestions, hints, tips or links to relevant articles would be much appreciated. Searching the forums didn't seem to yield anything that I could recognise as relevant.

mikejg
12th July 2006, 11:12 AM
Extra info - from my phpinfo() readout: (sorry about the length)

Session Support enabled
Registered save handlers files user
Registered serializer handlers php php_binary wddx

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 Off Off
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 1000 1000
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 5 5
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /var/lib/php/session /var/lib/php/session
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid 0

ibbo
12th July 2006, 12:16 PM
Do you call "session_start();" before assigning to the session?

Also I would use "$_SESSION['user'] = $row; " And you can then access them via "$_SESSION['user']["fname"]" etc.

Ibbo

BandC
12th July 2006, 03:51 PM
I second what ibbo says. You need to call session_start().

First things first, put some echo statements right before and after you set and check your session variables to see if you really set them. You can also use isset() to check to see if you really set them. See documentation in php.net.