Sessions, and a Session question
| From: | Nold, Mark | Date: | Tue, 11 Jul 2000 06:32:09 +0000 |
| Subject: | Sessions, and a Session question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5861@lists.php.net to get a copy of this message | ||
----------------------------------------------------------------------------
-----------------
Disclaimer: The information contained in this email is intended only for the
use of the person(s) to whom it is addressed and may be confidential or
contain legally privileged information. If you are not the intended
recipient you are hereby notified that any perusal, use, distribution,
copying or disclosure is strictly prohibited. If you have received this
email in error please immediately advise us by return email at
postmaster@normandy.com.au and delete the email document without making a
copy.
----------------------------------------------------------------------------
-----------------
Bit of a "me too", but this is something i just figured out.
The beauty of this is you can have
session_start();
session_register("x");
session_register("y");
session_register("z");
In a prepended file and you will now have a set of global variables $x, $y,
$z that follow your user everywhere, with no extra work (as long as you are
happy with cookies). A nice way of using this is to use arrays such as
$USER_INFO registered. Now you can keep on adding more detail to $USER_INFO
such as $USER_INFO["userid"], $USER_INFO["name"], $USER_INFO["theme"]
or
whatever.
The question i have, is how could i make these variables "Protected" so no
developer on my site decides that s/he wants to set
$USER_INFO["userid"] = strtoupper($USER_INFO["userid"])
Whilst a simple change may not match the db or whatever.
So basically once the user is logged in i want $USER_INFO to remain the
same.
Any ideas?
mn
-----Original Message-----
From: Carroll Barrett [mailto:cbarrett@inalt.com]
Sent: Tuesday, July 11, 2000 2:37 AM
To: Brian T. Allen; Ray Parish; php-general@lists.php.net
Subject: Re: [PHP] Sessions
Brian/Ray,
That's not how sessions work. A registered variable's value is
saved at the end of the script, not when it is registered. Look
at these 2 scripts:
session1.php
<?php
session_start();
$x="Empty";
session_register("x");
$x="Full";
header("Location: session2.php");
?>
session2.php
<?php
session_start();
echo("x = $x");
?>
The result of calling session1.php in my browser is
x = Full
This would not be true if a variable's value was saved when it
was registered instead of at the end of the script.
Regards,
Carroll Barrett
Regards,
Carroll Barrett
-----Original Message-----
From: Brian T. Allen <brian@purenetfx.com>
To: Ray Parish <rparish@digitalwebzone.com>;
php-general@lists.php.net <php-general@lists.php.net>
Date: Monday, July 10, 2000 1:21 PM
Subject: Re: [PHP] Sessions
>At first glance it looks like you are incrementing $count AFTER
you are
>putting it into the session. So you visit the page, count = 0,
you store 0
>in the session, increment to 1, then display 1.
>
>If you increment first, you would visit the page, count = 0,
increments to
>1, stores 1 in the session, and displays 1. The next time it
would
>increment to 2, etc...
>
>
>> <?
>>
>> // File name: count_me.php
>>
>> // if a session does not yet exist for this user,
start one
>>
>> session_start();
>> session_register('count');
>>
>> $count++;
>>
>> echo "<p>You've been here $count times. Thanks!</p>";
>> ?>
>>
>> I have this sample script that DOES NOT increament up each
time I click
>> refresh? It stays at 1?
>> Thanks
>> Ray
>>
>>
>>
>> --