Solved

php 5.2 register_globals setting not functionning

Posted on 2007-03-26
5
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code not executing correctly. 3 43
How do I add date to text file name 15 28
Format Date 7 28
Considerations PHP using multiple locations 9 34
This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 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