Author |
Message |
Vendethiel Board Member

Joined: 26 Oct 2014
      Posts: 215

|
Posted: Mon Feb 18, 2019 1:10 pm Post subject: PHP7 migration: magic_quotes |
|
|
First part of the "phpBB2 to PHP7 migration" guide.
This one is for the magic quotes feature, that errors out on recent PHPs.
For history's sake: back when PHP was much younger, a lot of people misused some of its features, which led to well-known SQL injection issues. So PHP introduced a feature to try and protect from them: it inserted \ before every ' so you wouldn't break out of SQL queries.
This is the reason for a whole lot of "preg_replace" in the whole of phpBB's $sql code.
Since this feature was server-dependant, there's code in common.php to detect whether it's enabled or not. This code errors out in PHP7+.
OPEN
FIND & REMOVE Code: | set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
FIND Code: | if( !get_magic_quotes_gpc() ) |
REPLACE WITH |
|
Back to top |
|
 |
Jim_UK Board Member

Joined: 19 Nov 2008
            Posts: 628 Location: North West UK

|
Posted: Mon Feb 18, 2019 2:28 pm Post subject: Re: PHP7 migration: magic_quotes |
|
|
If all the changes are applied to the code we have now and we are still running on PHP5 will the board still run or can those changes only be applied when we have to go to PHP7?
I am going to copy all the posts you make into a file ready for the day my host says I have to move to PHP7
Jim |
|
Back to top |
|
 |
Vendethiel Board Member

Joined: 26 Oct 2014
      Posts: 215

|
Posted: Mon Feb 18, 2019 3:40 pm Post subject: Re: PHP7 migration: magic_quotes |
|
|
This change is compatible with any PHP version you know has magic_quotes disabled.
This feature was deprecated in 5.3.0, from 2009. But AFAIK, the feature was disabled by default on most hosts starting with PHP4 (released in 2000).
If for some reason you absolutely must support PHP4, there's a way to make it work as well, but it'd make zero sense to. |
|
Back to top |
|
 |
Phineus Board Member

Joined: 21 Jul 2019
 Posts: 11

|
Posted: Thu Jul 25, 2019 1:11 pm Post subject: Re: PHP7 migration: magic_quotes |
|
|
I don't know if there's an advantage to one way or the other.
OPEN
FIND Code: |
set_magic_quotes_runtime(0); // Disable magic_quotes_runtime |
REPLACE WITH Code: |
if (!function_exists('set_magic_quotes_runtime')) {
function set_magic_quotes_runtime($new_setting) {
return true;
}
} |
|
|
Back to top |
|
 |
Vendethiel Board Member

Joined: 26 Oct 2014
      Posts: 215

|
Posted: Sat Jul 27, 2019 3:07 pm Post subject: Re: PHP7 migration: magic_quotes |
|
|
Your version is not enough (since get_ function is still called), and I’d rather just remove old outdated code rather than reintroduce a dummy function |
|
Back to top |
|
 |
Phineus Board Member

Joined: 21 Jul 2019
 Posts: 11

|
Posted: Sun Jul 28, 2019 1:12 am Post subject: Re: PHP7 migration: magic_quotes |
|
|
Understood. Thanks. |
|
Back to top |
|
 |
|