not getting SESSION ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

not getting SESSION ?

Post by saumya »

Hi I am trying to study SESSIOn on PHP but could not really get into it.
on my first page, I have

Code: Select all

session_start();
session_register("s_work_order_no");
$s_work_order_no = 'a001_002';
when I go to another page and try to get to the varibale, I could not get it :(

Code: Select all

session_start();
echo $s_work_order_no;
it gives me following error

Code: Select all

Notice: Undefined variable: s_work_order_no test.php on line 49
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

Hi, thank you so much.Thats a great point.
But still I am not getting it to work :(
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

He's saying not to use session_register() ... instead, assign and retrieve session variables using the $_SESSION superglobal:

Code: Select all

<?
session_start();
$_SESSION['foo'] = "bar";
?>
Next page...

Code: Select all

<?
session_start();
echo $_SESSION['foo'];  // prints "bar"
?>
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

I got that I tried it.But no luck :(

Code: Select all

session_start();
$_SESSION["s_work_order_no"];
$s_work_order_no = 'a001_002';
Then

Code: Select all

session_start();
echo '<br/>'.$_SESSION['s_work_order_no'];
Thank you
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Almost.. just assign it like this:

Code: Select all

<?
session_start();
$_SESSION["s_work_order_no"] = 'a001_002';
?>
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

hi aaronhall,that worked as sweet.:wink: :P
Thank you so much.You saved me a headache.
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

Hey guys one more question, Do I still need to send the SID in the browser query string?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

saumya wrote:Hey guys one more question, Do I still need to send the SID in the browser query string?
Well that depends... You will have to read more about sessions and how they work, that would be the best answer I could give you - seriously :wink:
Check out http://shiflett.org/articles

After some reading, you'll understand why I suggest you dont send the SID withing the query string - use cookies instead (user must have cookies enabled for that of course).
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

hi Oren,
thats really some serious stuff. :)

Now, my question is if I donot send query string and users never enable cookies, then is it possible to run session? :roll: 8O
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

The user must supply the session id in some way, if it's not supplied with a cookie or in the query string, how will PHP know what session data belongs to this user?
saumya
Forum Contributor
Posts: 193
Joined: Sun Jan 30, 2005 10:21 pm

Post by saumya »

Thank you Oren, I got the idea.
chakhar86
Forum Commoner
Posts: 45
Joined: Mon Jun 05, 2006 1:36 am
Contact:

Post by chakhar86 »

I've never sent session ID to the server but it works completely fine...
Is PHP will treat single user as single child in its process?
So the session ID won't be exchanged with other user???
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

sessions by default are stored in a flatfiles located somewhere in your server, so in theory depending on your server's security and setup it is possible for people to read others sessions. I believe the search term you are looking for is session hijacking
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

chakhar86 wrote:I've never sent session ID to the server but it works completely fine...
Is PHP will treat single user as single child in its process?
So the session ID won't be exchanged with other user???
Sorry, I couldn't understand your question. Can you ask again please?
Post Reply