Re: FUDForum 3.0 SQL errors with SQLite [message #160709 is a reply to message #160707] |
Thu, 15 October 2009 23:48 |
dewaard
Messages: 6 Registered: November 2004 Location: The Netherlands
Karma:
|
Junior Member |
|
|
Thanks a lot for your reply. I'm running php5 using FastCGI with a Lighttpd webserver (again, to conserve memory on my VPS). My system is using IPv4, but supports and recognizes IPv6 (if I run ifconfig I actually see both an IPv4 and IPv6 address for eth0). After reading your post I wrote this code to test some values:
Quote: | <?php
include("/[removed]/FUDforum/include/core.inc");
print var_dump(get_ip());
print "<br />";
print var_dump($_SERVER['HTTP_X_FORWARDED_FOR']);
print "<br />";
print var_dump($_SERVER['REMOTE_ADDR']);
print "<br />";
print var_dump(substr($_SERVER['REMOTE_ADDR'], 7));
print "<br />";
print var_dump(ip2long(get_ip()));
?>
|
With this output (the IP was my actual address, but changed it to 127.0.0.1 it for privacy reasons):
Quote: | string(20) "::ffff:127.0.0.1"
NULL
string(20) "::ffff:127.0.0.1"
string(13) "127.0.0.1"
bool(false)
|
Apparently, the remote address is some strange hybrid between IPv4 and IPv6. I brushed off my rusty PHP skills (Python user here, sorry) and created a quick and dirty fix (that works for me, so far), by changing the return line of get_ip to:
Quote: | return (isset($_SERVER['REMOTE_ADDR']) ? substr($_SERVER['REMOTE_ADDR'], 7) : '0.0.0.0');
|
Obviously, a clean solution would run regular expressions to check if it concerns a IPv4, IPv6 or this weird hybrid address. I would suggest a solution where the current mechanics are followed if the IP matches IPv4, but 0.0.0.0 is returned if it isn't (without checking for IPv6/hybrid). That will at least suppress errors like I encountered, without excessive performance trade offs that would occur when checking the value against IPv6 or the weird hybrid on my system.
IPv6 users or people who have the same prefix to the address my system has should probably convert the value of $_SERVER['REMOTE_ADDR'] to valid IPv4 centrally (maybe using a configuration option set automatically during installation?) if they want a different value from 0.0.0.0.
If you want, I'll gladly volunteer to prepare a patch to your specifications to resolve the issue.
[Updated on: Thu, 15 October 2009 23:51] Report message to a moderator
|
|
|