Solved

php 5.2 register_globals setting not functionning

Posted on 2007-03-26
5
546 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
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 …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

840 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