Solved

php 5.2 register_globals setting not functionning

Posted on 2007-03-26
5
542 Views
Last Modified: 2013-12-13
PHP 5.2, Windows 2003, Apache 2.0

Register_Globals are OFF in php.ini but global variables are still enabled. This is my test script:
No .htaccess files are present.

<?php
$test="hello world";
testfunc();

function testfunc()
{
global $test;
echo $test;
}
?>

It produces the following output: hello world

Is there another setting that manages the global variables for PHP???
0
Comment
Question by:vanauden
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:TeRReF
ID: 18795622
Yes, this :)

global $test;

Remove that and it won't work anymore
0
 
LVL 29

Accepted Solution

by:
TeRReF earned 250 total points
ID: 18795643
The global keyword takes vars from the gobal scope inside the function. You cannot disable that, it's part of the language constructs.

Register globals is a different story, that is evil and should be off indeed...
0
 
LVL 24

Assisted Solution

by:glcummins
glcummins earned 250 total points
ID: 18795672
You can use the global keyword to make any script variable available in within a function, regardless of the register_globals setting. That setting is for situations like this:

A script is called with this query string: index.php?username=Bob

Now if register_globals is on, a variable named '$username' is automatically created:
<?php
echo $username; // Output is 'Bob'
?>

Obviously this is a security concern in some cases, because you don't want variables created without your explicit instructions. That is why register_globals is now off by default.
0
 
LVL 1

Author Comment

by:vanauden
ID: 18796312
ok I understand -

follow up question:

does the global keyword also work in php version 4??
0
 
LVL 24

Expert Comment

by:glcummins
ID: 18796372
According to the PHP manual on this topic, the keyword does exists in PHP 4:

http://www.php.net/global
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question