phpbb 3.1 passing variable between 2 pages - php

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

Related

PHP not reading XML file [duplicate]

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

Is there a way to protect the $_SERVER global from modification?

I would like to prevent php scripts from being able to modify the contents of the $_SERVER global.
Specifically I don't want to allow
unset $_SERVER['foo'];
but it would be nice to forbid any modification, e.g. a module or php.ini declaration.
Is there one?
If you're in control of the root level script you could just copy it:
$_my_server = $_SERVER;
I think it would be helpful to know your reason for this; the $_SERVER variable shouldn't be modified by included scripts, because there's rarely a reason for someone to need to modify it. It's generated at run-time so any changes aren't persisted to subsequent runs of the script.
Also your extra point about php.ini declarations is a bit more confusing - the point of many componentes of $_SERVER is to inform scripts about those declarations, so having it send fake data would seem a very odd use case and maybe not possible.
Not as far as i'm aware.
If you are relying on the contents of $_SERVER throughout you code, and dont want other code (plugin?) to modify it, your best option is to make a copy during the bootstrap stage of your application, then use that copy throughout your code:
$serverDetails = $_SERVER;
$foo = $serverDetails['foo'];

Prevent Wordpress from applying magic quotes to CI cookie without changing core file

Our Problem: We have a CodeIgniter app within the Wordpress directory and are using Wordpress' functions to generate the navigation. However, we found that Wordpress renders the Codeigniter Cookie useless due to the wp_magic_quotes function located in wp-includes/load.php -- specifically this line:
$_COOKIE = add_magic_quotes( $_COOKIE );
Our current solution is to modify the wp_magic_quotes function directly using array_walk to loop over the $_COOKIE variable and apply add_magic_quotes to all keys except for our CI session like so:
function ci_ignore_magic_quotes($value,$key)
{
if($key != "ci_session")
{
stripslashes_deep($value);
}
}
and changing the aforementioned line in wp_magic_quotes to:
array_walk($_COOKIE, 'ci_ignore_magic_quotes');
//$_COOKIE = add_magic_quotes( $_COOKIE );
However, this is obviously problematic because these changes will be discarded with the next WP upgrade.
Is it possible to address our problem this without modifying this core file?
You cannot edit those functions-- wp_magic_quotes and wp_unregister_GLOBALS-- without editing the core file.
This is basic PHP. You cannot redefine a function. Trying to define, or redefine, that function anywhere other than in that core file will result in an error because whatever you do, other than edit the core file, it will be defined twice in the code.
Nor are there hooks in those functions that might help you. Sorry. Three may be ways to do what you want if you explained what you want to accomplish instead of asking how to do implement some particular solution. You may have an x/y problem with this question.

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!)

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