Welcome Guest ( Log In | Register )




                Web Hosting

 
Reply to this topicNew Topic
Reading Data From Sessions
shadow-x
post Apr 11 2006, 02:31 PM
Post #1


Newbie [ Level 2 ]
Group Icon

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 sad.gif <BR><BR>";
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?
Go to the top of the page
 
+Quote Post
Hercco
post Apr 11 2006, 08:39 PM
Post #2


Super Member
Group Icon

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.
Go to the top of the page
 
+Quote Post
shadow-x
post Apr 11 2006, 09:02 PM
Post #3


Newbie [ Level 2 ]
Group Icon

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]

rolleyes.gif Well I am blonde!
Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   5 Kushika 2,982 2nd January 2009 - 07:39 PM
Last post by: iG-Zia
No New Posts   11 sandeep 2,307 15th December 2008 - 07:04 AM
Last post by: iG-robert
No New Posts   0 Leveecius 180 7th December 2008 - 04:05 AM
Last post by: Leveecius
No New Posts   0 Jonnie79 99 2nd December 2008 - 11:40 PM
Last post by: Jonnie79
No New Posts   8 darkool 3,046 11th November 2008 - 10:03 PM
Last post by: Guest
No New Posts   7 tansqrx 592 9th October 2008 - 11:21 AM
Last post by: Atomic0
No New Posts   15 Grafitti 1,428 10th September 2008 - 06:54 AM
Last post by: Guest
No New Posts   11 Alexandre Cisneiros 2,122 4th September 2008 - 06:45 AM
Last post by: Guest
No New Posts   2 Mordent 301 25th July 2008 - 07:03 PM
Last post by: Mordent
No New Posts   8 Nivedita 1,369 12th June 2008 - 01:58 PM
Last post by: iGuest
No New Posts   6 xboxrulz 514 9th June 2008 - 05:35 PM
Last post by: xboxrulz
No New Posts   5 fabiocardoso 1,429 29th May 2008 - 02:46 PM
Last post by: iGuest
No New Posts   1 Mordent 379 19th April 2008 - 07:52 AM
Last post by: Jared
No New Posts   13 pat23 2,284 16th April 2008 - 02:39 PM
Last post by: iGuest
No New Posts   0 FirefoxRocks 324 24th March 2008 - 05:42 PM
Last post by: FirefoxRocks