Register Globals update code.

Get help with installation and running phpBB 3.3.x here. Please do not post bug reports, feature requests, or extension related questions here.
gavo
Registered User
Posts: 93
Joined: Sat Jun 23, 2007 10:44 am

Register Globals update code.

Post by gavo »

Hi, how can this code be updated so it doesnt use globals?

Thanks

Code: Select all

if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3945
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay

Re: Register Globals update code.

Post by Kailey »

Hello,

Can you provide a link to your board?
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules
If you have any questions about the rules/customs of this website, feel free to send me a PM.

My little corner of the world | Administrator @ phpBB Modders
User avatar
Helter Skelter
Registered User
Posts: 181
Joined: Tue Jan 25, 2005 8:22 am
Location: integramod.com

Re: Register Globals update code.

Post by Helter Skelter »

Code: Select all

if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $remoteAddr = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $remoteAddr = $_SERVER['REMOTE_ADDR'];
}
Instead of directly modifying $_SERVER['REMOTE_ADDR'], assign the value of $_SERVER['HTTP_X_FORWARDED_FOR'] to a new variable named $remote_addr so it no longer relies on register_globals and instead uses a separate variable to store the value of the remote address.

or you can use the null coalescing operator directly in the assignment

Code: Select all

$remoteAddr = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'] ?? null;
gavo
Registered User
Posts: 93
Joined: Sat Jun 23, 2007 10:44 am

Re: Register Globals update code.

Post by gavo »

Thanks for the reply, I gave up with this route and used mod_remoteip

Return to “[3.3.x] Support Forum”