WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Problem passing session variables
Categories : Sessions, PHP Update Picture
Randy Phillips
Date : Mar 21st 2002
Grade : 3 of 5 (graded 9 times)
Viewed : 18756
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Randy Phillips
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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.



GuestBook Light - a plug and play application for any website.
Categories : PHP, Complete Programs, Filesystem, Sessions
A beginner's session handling class
Categories : PHP, PHP Classes, Sessions, Beginner Guides
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
A login page that require username, password and userlevel.
Categories : PHP, Security, Sessions, MySQL, Databases
Optimized Online users class
Categories : PHP, PHP Classes, Sessions
PHP4 session helper HTML file.
Categories : PHP, Java Script, HTML and PHP, Sessions
Authenticator for Exchange Server LDAP
Categories : PHP, Authentication, LDAP, Security, Sessions
Simple Session example
Categories : PHP, Beginner Guides, Sessions
Form Security - Match A Value For Success
Categories : PHP, Authentication, HTML and PHP, Sessions, Security
Cross Browser Session Starter
Categories : PHP, Sessions, Cookies
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
A simple PHP login script that you can modify to suite your needs. It use a session to store data in a session file submited by the page.
Categories : PHP, Sessions, Security, Authentication
XDT Topsite (Gold v1.0)
Categories : Databases, CSS, PHP, HTML and PHP, Sessions
Simple PHP Form Auto Generation based on MySQL query
Categories : PHP, Form Processing, Databases, MySQL, Sessions