PHP not reading XML file [duplicate] - php

Can someone give some examples of what register_globals are?
And is global $user_id; considered a register global?

The register_globals directive:
register_globals is an internal PHP setting which registers the $_REQUEST array's elements as variables. If you submit a value in a form, via POST or GET, the value of that input will automatically be accessible via variable in the PHP script, named after the name of the input field.
In other words, if you submitted a form containing a username text field, the expression ($username === $_POST['username']) at the very beginning of the script would return true.
Its notoriety is attributed to the fact that it opens lots of security holes, especially for people that follow anything less than a strict coding style from a security perspective.
Classic example:
if(user_is_admin($user))
{
$authorized = true;
}
if($authorized)
{
// let them do anything they want
}
Now, if you visited that script in a web browser and the server had register_globals on, you could simply append ?authorized=1 to the URL and god-mode would be enabled!
The global keyword:
global is a keyword has little to do with register_globals.
Here is an example of its use:
$foo = 'bar';
baz();
function baz()
{
echo $foo; // PHP warns you about trying to use an uninitialized variable
// and nothing is output (because $foo doesn't exist here)
}
buzz();
function buzz()
{
global $foo; // Enables the use of $foo in this scope
echo $foo; // Prints 'bar' to screen
}

Everyone mentioning GET, POST, REQUEST, COOKIE has effect on register_globals=on.
I'm just writing this to let you know that -
$_SESSION will be affected aswell because of register_globals=on.
http://php.net/manual/en/security.globals.php
That means - if you do as following -
$_SESSION[x] = 123;
$x = 'asd';
echo $_SESSION[x];
The output will be asd.
And this will cause serious security issues and bugs. I have experienced such a bad thing recently during using Hostgator shared hosting. By Default they have register_globals=on.

When you have register_globals=on, anything passed via GET or POST or COOKIE automatically appears to be global variable in code, this might have security consequences.
I.e. you click on url test.php?access_level=100 and you'll have $access_level = 100 in PHP.
When you do global $somevar - you are making your own global variable, which usually is not a big issue.

The register_globals setting controls how you access form, server, and environment. variables.
register_globals=On :
You can access form attribute without Global Arrays ( GET[], POST[] & REQUEST[] )
example: http://www.example.com/one.php?myinput=abc
You can access directly in one.php
echo $myinput; // abc
register_globals=Off :
You have to access all attributes only by Global Arrays.
example: http://www.example.com/one.php?myinput=abc
You have to access in one.php
echo $_GET['myinput']; //abc

As I understand it, if you have register globals turned ON, then anything passed in a GET or POST gets automatically translated into a variable in PHP.
for example:
http://www.domain.com/vars.php?myvar=123
without any further coding this would automatically get turned into a variable available to the rest of your php code
$myvar //with a value of 123
With registered globals OFF, data passed in via GET or POST is NOT automatically translated into a variable, rather, you need to request it using the Superglobals $_GET, $_POST, and $_REQUEST, etc.
http://php.net/manual/en/security.globals.php provides some further information as to the security implications of this.
Others can feel free to correct me if I'm wrong.
edit:
in relation to your question re global $user_id;, this does not create a 'global' in the sense of 'register_globals'. It simply alters the scope of a variable within the PHP code.
For information re scope, see: http://php.net/manual/en/language.variables.scope.php

Global variables in php are variables that are always accessible. They are also known as superglobals. They are built in variables that are always available regardless of the scope.
There are nine superglobal variables in PHP. Some of these are relevant to this discussion.
$_REQUEST
$_POST
$_GET
$_COOKIE
Now, let's focus on the $_REQUEST superglobal. It is used to collect data after submitting an HTML form by user using the POST method.
$_POST and $_REQUEST could be used loosely interchangeably. But $_REQUEST also contains $_GET and $_COOKIE along with $_POST so you are never sure if your data came from a web form.
Now, as pointed out by #Tim register_globals is an internal PHP setting which registers the $_REQUEST array's elements as variables. It is also known as a flag in your php setting. It is typically set in the PHP configuration file known as php.ini file. This setting can have two values.
“on”
“off”.
An “on” value means that PHP will automatically create global variables for many server variables as well as query string parameters. This is not good and is a security risk.

Register Globals :
register_globals
The feature causes data passed to a PHP script via cookies or GET and POST requests to be made available as global variables in the script.
Default Value : "0"
Changeable : PHP_INI_PERDIR
register_globals is affected by the variables_order directive.
NOTE:
This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

register_globals is one of the parameters of php.ini file.The file was coming from "On" mode before PHP 5.3.8 version.If you change register_globals from Off to On, there would be some criticals about vulnerability of website.Register_globals's feature is that you can use variables without $_GET and $_POST variables.So, Any data which comes from form or URL line you can use the variable not need like $_GET or $_POST variables.Example we have this form :
<?php
if(isset($_POST["myinput"])){
echo $_POST["username"];
}?>
<form action="" method="post">
<input type="text" name="username">
<input type="hidden" name="myinput">
<input type="submit" value="Submit">
</form>
When you submitted the form you can see your username but when you change the situation of register_globals to "On" you have not written $_POST["username"]; you can access directly to the username variable by writing this code echo $username

Related

phpbb 3.1 passing variable between 2 pages

With phpbb3.1 it appears they have disabled more superglobals.
I have tried passing a variable between using sessions, but have had no success.
$_SESSION['example'] = 'example';
$example = $_SESSION['example'];
Nothing is stored because nothing is there due to phpbb disabling superglobals. What's the next best and most secure way to pass variables in between pages?
You might want to take a look at this answer, where I explained that you can also temporarily (or globally) switch Superglobals back:
Globally
Open the /phpbb/config/parameters.yml file and change the core.disable_super_globals key from true to false.
Programmatically
This is a sample code that can be used to temporarily enable superglobals (per-request scope):
// temporarily enable superglobals
$request->enable_super_globals();
// TODO: do your stuff here.
// disable superglobals again
$request->disable_super_globals();
You can also read this blog post that I wrote on this topic for further info.
I'm not sure if $_SESSION is included, but try phpBBs request class...
$example = $request->variable('example','');
Docs for the class are here - https://wiki.phpbb.com/PhpBB3.1/RFC/Request_class

php session and other variable bug, it is normal?

session_start();
$_SESSION["somevariable"] = "blablabla";
print $_SESSION["somevariable"]."<br>";
$somevariable = "some bug";
print $_SESSION["somevariable"]."<br>";
output:
blablabla
some bug
I creata some session variable ($_session["data"]) and then i create some tipical variable ($data) then $_session variable are overwrite.
Our server php version is 5.2.5,Zend Engine v2.2.0
Sorry for my english, thanks for help
You have register globals turned on. This causes the declaration of $somevariable to overwrite the $_SESSION['somevariable'] since they point to the same place.
You should turn this off as it is deprecated and can cause issues like you are experiencing.
About superglobals. Exactly this line:
If the deprecated register_globals directive is set to on then the variables
within will also be made available in the global scope of the script.
For example, $_POST['foo'] would also exist as $foo.
check on here codeviper
You can change or update session value anytime like normal variable value change but in this case you can not because its prevent you result is override. the reason behind Global php variable securrity ON`.
e.g. $_SESSION['item'] is the same as $item
You can set on modify php.ini file:
session.bug_compat_42 = On
modify to:
session.bug_compat_42 = Off
Hope this help you!
you are over writing the data to the variable,session will remain untill constant in a page untill it is over writted forcefully by something.

global and $_SESSION variables with the same name are the same

I got a piece of code:
$_SESSION['cms_lang'] = 2;
global $cms_lang;
$cms_lang[1] = 'en';
Error:
Cannot use a scalar value as an array
Problem is that, I really don't know why server sees my global variable as the same as $_SESSION variable. I used this piece of code a couple of times and never had problem with that. I guess it must depends of settings on server. Can anyone know how to force server to not take global and session variables with the same name as the same?
You may read up on the PHP configuration setting register_globals which enables this behavior.
Also, read about why you should disable it (and generally, upgrade your PHP version!)

Infer the correct difference between a global and a superglobal variable in PHP

I know SUPERGLOBAL variables are associative arrays available in any scope throughtout the script and according to the following excerpt from a post (http://www.sitepoint.com/forums/showthread.php?68618-PHP-global-and-superglobal)
Excerpt:
the difference between "global" and "superglobal" is that a global variable is defined at the top level, but is not initially accessible inside a function, whereas a superglobal is automatically available anywhere within the code.
Now the text i am referring to says (about NATIVE PHP SESSIONS):
PHP creates its SID whenever you use the session_start() function, and also by default if you use certain other session-related functions, such as session_register(). The value of SID is kept in a global variable name PHPSESSID.
Now I am not sure as to how PHPSESSID is accessible. Is it simply $phpsessid or $_SESSION['PHPSESSID'].
Please clear this for me.
I am sure there is no $_SESSION['PHPSESSID'] nor $phpsessid. Maybe $phpsessid exists if register_globals are on.
In order to obtain your session id you can either use $_COOKIE['PHPSESSID'] or session_id(). You can check the documentation.

What are register_globals in PHP?

Can someone give some examples of what register_globals are?
And is global $user_id; considered a register global?
The register_globals directive:
register_globals is an internal PHP setting which registers the $_REQUEST array's elements as variables. If you submit a value in a form, via POST or GET, the value of that input will automatically be accessible via variable in the PHP script, named after the name of the input field.
In other words, if you submitted a form containing a username text field, the expression ($username === $_POST['username']) at the very beginning of the script would return true.
Its notoriety is attributed to the fact that it opens lots of security holes, especially for people that follow anything less than a strict coding style from a security perspective.
Classic example:
if(user_is_admin($user))
{
$authorized = true;
}
if($authorized)
{
// let them do anything they want
}
Now, if you visited that script in a web browser and the server had register_globals on, you could simply append ?authorized=1 to the URL and god-mode would be enabled!
The global keyword:
global is a keyword has little to do with register_globals.
Here is an example of its use:
$foo = 'bar';
baz();
function baz()
{
echo $foo; // PHP warns you about trying to use an uninitialized variable
// and nothing is output (because $foo doesn't exist here)
}
buzz();
function buzz()
{
global $foo; // Enables the use of $foo in this scope
echo $foo; // Prints 'bar' to screen
}
Everyone mentioning GET, POST, REQUEST, COOKIE has effect on register_globals=on.
I'm just writing this to let you know that -
$_SESSION will be affected aswell because of register_globals=on.
http://php.net/manual/en/security.globals.php
That means - if you do as following -
$_SESSION[x] = 123;
$x = 'asd';
echo $_SESSION[x];
The output will be asd.
And this will cause serious security issues and bugs. I have experienced such a bad thing recently during using Hostgator shared hosting. By Default they have register_globals=on.
When you have register_globals=on, anything passed via GET or POST or COOKIE automatically appears to be global variable in code, this might have security consequences.
I.e. you click on url test.php?access_level=100 and you'll have $access_level = 100 in PHP.
When you do global $somevar - you are making your own global variable, which usually is not a big issue.
The register_globals setting controls how you access form, server, and environment. variables.
register_globals=On :
You can access form attribute without Global Arrays ( GET[], POST[] & REQUEST[] )
example: http://www.example.com/one.php?myinput=abc
You can access directly in one.php
echo $myinput; // abc
register_globals=Off :
You have to access all attributes only by Global Arrays.
example: http://www.example.com/one.php?myinput=abc
You have to access in one.php
echo $_GET['myinput']; //abc
As I understand it, if you have register globals turned ON, then anything passed in a GET or POST gets automatically translated into a variable in PHP.
for example:
http://www.domain.com/vars.php?myvar=123
without any further coding this would automatically get turned into a variable available to the rest of your php code
$myvar //with a value of 123
With registered globals OFF, data passed in via GET or POST is NOT automatically translated into a variable, rather, you need to request it using the Superglobals $_GET, $_POST, and $_REQUEST, etc.
http://php.net/manual/en/security.globals.php provides some further information as to the security implications of this.
Others can feel free to correct me if I'm wrong.
edit:
in relation to your question re global $user_id;, this does not create a 'global' in the sense of 'register_globals'. It simply alters the scope of a variable within the PHP code.
For information re scope, see: http://php.net/manual/en/language.variables.scope.php
Global variables in php are variables that are always accessible. They are also known as superglobals. They are built in variables that are always available regardless of the scope.
There are nine superglobal variables in PHP. Some of these are relevant to this discussion.
$_REQUEST
$_POST
$_GET
$_COOKIE
Now, let's focus on the $_REQUEST superglobal. It is used to collect data after submitting an HTML form by user using the POST method.
$_POST and $_REQUEST could be used loosely interchangeably. But $_REQUEST also contains $_GET and $_COOKIE along with $_POST so you are never sure if your data came from a web form.
Now, as pointed out by #Tim register_globals is an internal PHP setting which registers the $_REQUEST array's elements as variables. It is also known as a flag in your php setting. It is typically set in the PHP configuration file known as php.ini file. This setting can have two values.
“on”
“off”.
An “on” value means that PHP will automatically create global variables for many server variables as well as query string parameters. This is not good and is a security risk.
Register Globals :
register_globals
The feature causes data passed to a PHP script via cookies or GET and POST requests to be made available as global variables in the script.
Default Value : "0"
Changeable : PHP_INI_PERDIR
register_globals is affected by the variables_order directive.
NOTE:
This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
register_globals is one of the parameters of php.ini file.The file was coming from "On" mode before PHP 5.3.8 version.If you change register_globals from Off to On, there would be some criticals about vulnerability of website.Register_globals's feature is that you can use variables without $_GET and $_POST variables.So, Any data which comes from form or URL line you can use the variable not need like $_GET or $_POST variables.Example we have this form :
<?php
if(isset($_POST["myinput"])){
echo $_POST["username"];
}?>
<form action="" method="post">
<input type="text" name="username">
<input type="hidden" name="myinput">
<input type="submit" value="Submit">
</form>
When you submitted the form you can see your username but when you change the situation of register_globals to "On" you have not written $_POST["username"]; you can access directly to the username variable by writing this code echo $username

Categories