|
|
|
|
![]() ![]() |
Apr 11 2006, 02:31 PM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 26 Joined: 4-April 06 Member No.: 12,473 |
Hello everyone!
Before I start let me just say that ive read many threads on here about php and sessions, several tutorials and the php manual but I still cant find a solution to my problem. My problem is that when i try to read data from a session it just comes up blank, and an if statement to see if the variable is null returns true. The code im using is for a login script which checks the input from a user and compares it with the data in a database to log the user in, this works fine, also reading the data from the session works perfectly on the page which the session is generated by so the problem is when the user navigates to another page the variables dont seem to travel with them. The code I'm using to generate the sessions is this: QUOTE //define initial variables $user = $_POST['username']; $password = $_POST['password']; session_register(name,$user); session_register(status,"0"); //set variables $session['name'] = $user; $_session['status'] = "0"; to try and read the variables from another page ive used an included file with thise code: QUOTE session_start(); if($_session['name'] == NULL){ echo "no session is set echo $_session['name']; } else { echo "sesion is set for:"; echo $_session['name']; }; This returns "no session is set" which means that the variable is null. the data inside the session file is "name|N;chris|N;status|N;0|N;" I dont know if that helps to see what the problem is. So can anyone tell me why the variables aren't being read by the pages? |
|
|
|
Apr 11 2006, 08:39 PM
Post
#2
|
|
|
Super Member Group: Members Posts: 595 Joined: 4-September 04 Member No.: 228 |
The superglobal for sessions is $_SESSION not $_session or let alone $session. Latter two are just normal arrays created when you assign values to them.
So change the lines CODE $session['name'] = $user; $_session['status'] = "0"; To CODE $_SESSION['name'] = $user; $_SESSION['status'] = "0"; And your script should work. Also you do not need to use session_register() function. Simply assigning values to the superglobal array ($_SESSION) suffices. Session_register() works but it's usage is not recommended anymore. |
|
|
|
Apr 11 2006, 09:02 PM
Post
#3
|
|
|
Newbie [ Level 2 ] Group: Members Posts: 26 Joined: 4-April 06 Member No.: 12,473 |
[SHAME]
Oh deer, deer, me! I spent hours reading tutorials and everything else and forgot to realise it was case-sensitive. Well thank you so much atlast I can get somewhere now! [/SHAME] |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th December 2008 - 11:06 AM |