Page 1 of 1

Overriding commentInfo['ip']?

Posted: Sun Jan 20, 2013 12:17 am
by FishNiX
Hey all -

I'm trying to write in support for X-Forwarded-For without hacking core functions. I've been trying to work with the frontend_saveComment event hook. It looks like eventData and addData come through with some information about the comment, but setting

Code: Select all

eventData['ip'] = getenv('HTTP_X_FORWARDED_FOR') != '' ? getenv('HTTP_X_FORWARDED_FOR') : $_SERVER['REMOTE_ADDR'];
or

Code: Select all

addData['ip'] = getenv('HTTP_X_FORWARDED_FOR') != '' ? getenv('HTTP_X_FORWARDED_FOR') : $_SERVER['REMOTE_ADDR'];
doesn't override commentInfo. I'm not sure if this is possible? I don't really want to hack include/functions_comments.inc.php if I don't have to since it will make upgrades, etc harder.

Thanks!

Re: Overriding commentInfo['ip']?

Posted: Sun Jan 20, 2013 1:40 am
by garvinhicking
Hi!

Have you tried editing your serendipity_config_local.inc.php with somethin glike this:

Code: Select all

if (getenv('HTTP_X_FORWARDED_FOR') != '') {
  $_SERVER['REMOTE_ADDR'] = getenv('HTTP_X_FORWARDED_FOR');
}
then you shouldn't need to patch any code, because the proper IP you want is always contained in the right variable that everything accesses?

Regards,
Garvin

Re: Overriding commentInfo['ip']?

Posted: Sun Jan 20, 2013 3:25 am
by FishNiX
I didn't know I could do that. I'll give it a shot.

Thanks as always!
-c