Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

php 5.2 register_globals setting not functionning

Posted on 2007-03-26
5
Medium Priority
?
578 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 1000 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 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
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 dynamically set the form action using jQuery.

688 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