|
|
|
I tried every example of creating a session variable I could find and got the same
results with all of them. The session variables got set on the initial page but
that's the only place I could access them.
I'm certain others new to php have come across this and felt equally foolish after
discovering the solution.
This is a sample login page that starts a session when a user successfully logs in:
<?
$connect...
$sql ...
list($id,$first_name) = mysql_fetch_row($sql);
session_start();
if (!session_is_registered('user_id')) {
session_register('user_id');
$user_id = $id;
session_register('user_name');
$user_name = $first_name;
} else {
echo "<p>Session is set and should now be availalbe on all pages via
a cookie. At least that what I expected.";
}
//Sadly, these vars were only available on this page.
echo "<p>ID: $user_id";
echo "<p>Name: $user_name";
?>
Solution: What I did NOT do, and what is not made very clear in any literature I
came across, is that you need to set the session_start() function at the top of
EVERY page that will be in the session.
Hope this helps.
|
|
| Session Validation Methods (Security Checks) Categories : PHP, Sessions, Security | | | Securing Web Forms with Simple PHP-CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart)
Categories : PHP, Security, GD image library, Sessions | | | GuestBook Light - a plug and play application for any website. Categories : PHP, Complete Programs, Filesystem, Sessions | | | Security, Password lock out after three tries, authorization fails and is logged locked out of account till admin decides he will unlock it. Categories : Sessions, PHP, MySQL, PHP Options and Info | | | CSS style switcher Categories : PHP, CSS, HTML and PHP, Arrays, Sessions | | | Warning: Unknown(): A session is active. You cannot change the session module's ini settings at this time. in Unknown on line 0 Categories : PHP, Sessions, Databases, MySQL | | | Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | Simple Session example Categories : PHP, Beginner Guides, Sessions | | | Sessions and -enable-trans-sid Categories : PHP, PHP Configuration, PHP Options and Info, Sessions | | | Form Security - Match A Value For Success Categories : PHP, Authentication, HTML and PHP, Sessions, Security | | | Cross Browser Session Starter Categories : PHP, Sessions, Cookies | | | How to implement a session tracking system. Categories : PHP, Sessions, Variables | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | AITSH Statistics Categories : Complete Programs, Databases, HTML and PHP, Sessions, PHP | | | Simple PHP Form Auto Generation based on MySQL query Categories : PHP, Form Processing, Databases, MySQL, Sessions | |
|
|