Welcome Guest ( Log In | Register )



 
Reply to this topicStart new 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 topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Php, Sql Lite: Storing Session's Data?(1)
  2. Displaying Data From Mysql?(2)
  3. Help With Multi Tier Mysql Application Over Net(6)
  4. Php/mysql Data Display(3)
  5. Possible To Do?(7)
  6. PHP Sessions, Help(4)
  7. [PHP + MySQL] Encrypting Data(11)
  8. Sessions, Setting, Unsetting, Reading(5)
  9. Storing Data Into Xml With A Php Form(2)
  10. Need An Alternative To $http_post_data For PHP4(5)
  11. Data Passing - Re An Assignment For School - Please Help :)(8)
  12. Send XML Data To PHP Page(0)
  13. Proper Way To Grab User Data?(1)
  14. Retrieving Data And Displaying In Boxes(6)
  15. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  1. I'm Having Problems With Sessions(2)
  2. Getting Certain Parts Of A Record(17)
  3. Reading Files And Folders(1)
  4. Letting Users Add Mysql Data With Php(1)
  5. Reading Xml Data(2)


 



- Lo-Fi Version Time is now: 5th December 2008 - 11:06 AM