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
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.  >:(

Link to comment
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.  >:(

Link to comment
Share on other sites

$_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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.