Re: Global Variable Issues

From: Date: Fri, 04 Apr 2003 01:06:44 +0000
Subject: Re: Global Variable Issues
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-19279@lists.php.net to get a copy of this message
Try setting this variable as a session. Here is a piece of code used once a user has been validated against a MySQL dbase. ($uname was assigned from the login.html page) <? session_start(); $_SESSION['valid_user'] = $uname; ?> Then, on each page that requires a preson to be logged in to access, this goes at the top: <? //start the session session_start(); //see if this person is 'valid_user', if not, redirect to LOGIN.HTML if (!isset($_SESSION['valid_user'])){ header( "Location: login.html" ); } //if he is 'valid_user' then load the page as normal else { ?> NORMAL PAGE CODE HERE //allows me to assign a the info from 'valid_user' to a variable $uname=($_SESSION['valid_user']); <? //end ELSE statement } ?> "Cam" <ccrews@andrew.cmu.edu> wrote in message news:20030315011014.80958.qmail@pb1.pair.com... > Through past releases of PHP, I've developed with global variables on. > These days it's becoming the trend, for security & asthetics purposes, to > turn global variables off... Let's say I have a $status variable that > changes depending upon the user's actions on the previous page and displays > a message... > > Is there a way to propagate this variable through pages without 1) declaring > it as a global, 2) writing it to a cookie, 3) passing it through the URL or > 4) passing it through a form w/ POST? > > 1-globals are now off > 2-cookie writing is impracical & no desire to store 1 time information > client side > 3-displaying the status message in the URL (or a status id) would look > unprofessional and allow for user manipulation of the message they see by > editing the URL string > 4-not all my site's page transitions occur through forms, so I see no way to > use $_POST every time > > I appreciate any suggestions & hearing your thoughts, > > Cam > >

« previous php.windows (#19279) next »