Hello Marian, Monday, May 16, 2005, 9:36:17 AM, you wrote:
MB> I have been advised to quit using global MB> variables and don't know how MB> to write scripts without using them. I'm MB> rather baffled. Can someone MB> help me to see the light? I know it is a MB> security problem; my server is already a MB> target, and I need to tighten it up. Thanks in MB> advance. MB> Marian Hi Marian, Several alternatives were already mentioned... here's my spin: 1) In addition to $_POST and $_GET, if you're not using forms a quick-and-dirty way to refer to variables across functions would be inside $_SESSION, as in $_SESSION['myGlobal']='whatever' 2) Whenever possible, avoid reliance on global variables by passing needed information in function paramaters. If there are LOTS of paramaters, you could always pass them in an array. In other programming languages, large structures are usually passed as a reference, instead of a copy (in PHP you pass a reference by beginning the function parameter with an & -- read "References Explained" in the "Language Reference" section of the manual for more info... http://www.php.net/manual/en/language.references.php 3) (And this one is my favorite). If you've got a group of functions that all work with the same common variables, this is a good sign that you need to design a class (object). Say you've got a variable in the class definition called $myData ... each function inside the class then has access to $myData as $this->myData ... once again, in the manual... http://www.php.net/manual/en/language.oop.php (PHP 4) http://www.php.net/manual/en/language.oop5.php (PHP 5) -- Hope this helps, Gunther Community email addresses: Post message: [email protected] Subscribe: [EMAIL PROTECTED] Unsubscribe: [EMAIL PROTECTED] List owner: [EMAIL PROTECTED] Shortcut URL to this page: http://groups.yahoo.com/group/php-list Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/php-list/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
