Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

suPHP and $GLOBALS variable scope

General discussions related to php

Moderators: macek, egami, gesf

suPHP and $GLOBALS variable scope

Postby nguyenthu » Wed Jul 23, 2014 2:45 pm

Hello,
I'm trying to use $GLOBALS in suPHP but it can't give me data.
Example:
File setData.php
Code: Select all
<?php
$foo = "global VARIABLE";
$GLOBALS["foo"];
print_r($GLOBALS);
?>

Result is:
Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [PHPSESSID] => 2jnfmopbi5h2b8l169svie63b3 [__utma] => 196765739.194337144.1399825592.1404818990.1404840354.13 [__utmc] => 196765739 [__utmz] => 196765739.1399825592.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
[_ga] => GA1.3.194337144.1399825592 ) [_FILES] => Array ( ) [foo] => global VARIABLE )


File getData.php
Code: Select all
<?php
$GLOBALS["foo"];
print_r($GLOBALS);
?>

Result is:
Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [PHPSESSID] => 2jnfmopbi5h2b8l169svie63b3 [__utma] => 196765739.194337144.1399825592.1404818990.1404840354.13 [__utmc] => 196765739 [__utmz] => 196765739.1399825592.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
[_ga] => GA1.3.194337144.1399825592 ) [_FILES] => Array ( ) )



So in getData.php, when print $GLOBALS variable, it show nothing. Is this a problem of $GLOBALS in SuperGlobal when run suPHP?
And how can I use a variable for all request in suPHP?

Thank you very much!
nguyenthu
New php-forum User
New php-forum User
 
Posts: 1
Joined: Wed Jul 23, 2014 2:42 pm

Re: suPHP and $GLOBALS variable scope

Postby Strider64 » Thu Jul 24, 2014 1:22 pm

What exactly are you trying to do (accomplish)?

In my opinion using global variables is very bad practice and leads to sloppy code. Anytime you use server side variables you are opening yourself up to being hack, heck even sometimes when you write code properly you sometimes make yourself vulnerable. However, why open the door to the would-be-hacker?

So with that said, try to explain better in what you're trying accomplish.
User avatar
Strider64
New php-forum User
New php-forum User
 
Posts: 69
Joined: Sat Mar 23, 2013 8:24 am


Return to PHP General

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.