Jump to content

[SOLVED] a basic question about "sessions"


flunn

Recommended Posts

I seem to be missing something very basic about how "sessions" works.

 

If I understand it correctly, I should be able to use it to assign a value to a variable on one page and then access that value on another page.

 

But if I use this code on the first page

 

<?php

session_start();

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">

<html>

 

<head>

<title></title>

</head>

<body>

<?php

$_SESSIONS['test']= 1;

print $_SESSIONS['test'];

 

?>

</body>

</html>

 

"1" is returned,but if I try to access the value of $_SESSIONS['test'] on another page with this code:

 

<?php

session_start();

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">

<html>

 

<head>

<title></title>

</head>

<body>

<?php

if(isset($_SESSIONS['test']))

print $_SESSIONS['test'];

else

print 'not set';

 

?>

 

</body>

</html>

 

'not set' is returned.

 

Any advice would be much appreciated.

 

regards to all from

 

flunn

Link to comment
https://forums.phpfreaks.com/topic/82377-solved-a-basic-question-about-sessions/
Share on other sites

$_SESSIONS['test']= 1;

print $_SESSIONS['test'];

 

That's the same thing as doing:

 

$_X['key'] = 'val';

echo $_X['key'];

 

or $x = 1;

echo $x;

 

I am not stupid, I was saying how does $_SESSIONS echo anything. He claimed it returned 1 on his first page.

 

You're using $_SESSIONS just to let you know, thats a bad example you just gave me.

 

 

been coding for 3 years just to let you know.  >:(

$_SESSIONS['test']= 1;

print $_SESSIONS['test'];

 

That's the same thing as doing:

 

$_X['key'] = 'val';

echo $_X['key'];

 

or $x = 1;

echo $x;

 

I am not stupid, I was saying how does $_SESSIONS echo anything. He claimed it returned 1 on his first page.

 

You're using $_SESSIONS just to let you know, thats a bad example you just gave me.

 

 

been coding for 3 years just to let you know.  >:(

$_SESSIONS can be created just like $some_array can.

 

If you did:

$_some_array['test']= 1;
print $_some_array['test']; 

 

Would it not put out 1?

 

Yeah it would, but I thought he had the value already set in his $_SESSION, and he was just using it wrong.

 

I know understand what you mean, I was reading his script wrong i guess. :D

 

 

 

edit:

 

Here what i ment

 

 

$_SESSION['test'] = $_POST['some_field']; // lets say the value was 3

echo $_SESSIONS['test']; // ouputs 3

 

 

 

Thats what i thought he did, and I was getting confused.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.