Solved

php 5.2 register_globals setting not functionning

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
First name pregmatch 11 29
Why isn't this loading my css file 2 22
creating 2 user ID's 5 24
Paging Using PHP 7 32
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now