dannon Posted November 18, 2012 Share Posted November 18, 2012 Hi, I have been coding my site on Windows 7 and I have decided to check out Windows 8. And I'm guessing that windows 8 use IPv6 And when I test my website some of the features do not work correctly due to IPv6. It is because I use ip2long functions to check stuff and ip2long doesn't work for IPv6 IPs. Is it possible to convert IPv6 to IPv4 (i doubt it)? If not, then is there an alternative I method that I can use to convert IPs to longs? Quote Link to comment Share on other sites More sharing options...
dannon Posted November 18, 2012 Author Share Posted November 18, 2012 I have also used this: http://www.php.net/manual/en/function.ip2long.php#109298 . Will it still work with IPv6 ? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 18, 2012 Share Posted November 18, 2012 There are numerous ip2long6 and ip2bin6 custom function definitions in the user contributed notes section of the documentation of the ip2long function. Quote Link to comment Share on other sites More sharing options...
dannon Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) When I test http://www.php.net/m...2long.php#94477 I get some errors: ( ! ) Notice: Undefined variable: ipv6long in test.php on line 10 and ( ! ) Notice: Undefined variable: ipv6 in :\wamp\www\NewRetrite\test.php on line 28 I am not sure how to fix them. Can anyone help me out? Edited November 19, 2012 by dannon Quote Link to comment Share on other sites More sharing options...
berridgeab Posted November 19, 2012 Share Posted November 19, 2012 (edited) You need to turn off notices or define the variable before using it. I recommend turning notices off in production seen as variable initialisation is not required in PHP. Edit: Just looked at the code gain, make sure you haven't copy and pasted the variables testing the functions, you wont need them. Edited November 19, 2012 by berridgeab Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 19, 2012 Share Posted November 19, 2012 You need to turn off notices or define the variable before using it. I recommend turning notices off in production seen as variable initialisation is not required in PHP. Edit: Just looked at the code gain, make sure you haven't copy and pasted the variables testing the functions, you wont need them. This post makes little sense, and is downright wrong. Having the proper error reporting is imperative during the developmental stages, and since the OP has not specified what stage the site is in, I assume it's in development. Variable initialization is technically not required, but it should be exercised as good convention. Learning and exercising good practices from the beginning is very important in molding a "good programmer". OP, the errors you are being thrown are self explanatory. If you still cannot solve the issue after reviewing the code, post the updated code and we will be more than happy to help you further. Quote Link to comment Share on other sites More sharing options...
dannon Posted November 19, 2012 Author Share Posted November 19, 2012 (edited) This post makes little sense, and is downright wrong. Having the proper error reporting is imperative during the developmental stages, and since the OP has not specified what stage the site is in, I assume it's in development. Variable initialization is technically not required, but it should be exercised as good convention. Learning and exercising good practices from the beginning is very important in molding a "good programmer". OP, the errors you are being thrown are self explanatory. If you still cannot solve the issue after reviewing the code, post the updated code and we will be more than happy to help you further. Well, I have just made a test page to test the functions from the php.net site. Here is the code: <?php $ipv6 = "2001:4860:a005::68"; function ip2long6($ipv6) { $ip_n = inet_pton($ipv6); $bits = 15; // 16 x 8 bit = 128bit while ($bits >= 0) { $bin = sprintf("%08b",(ord($ip_n[$bits]))); $ipv6long = $bin.$ipv6long; $bits--; } return gmp_strval(gmp_init($ipv6long,2),10); } function long2ip6($ipv6long) { $bin = gmp_strval(gmp_init($ipv6long,10),2); if (strlen($bin) < 128) { $pad = 128 - strlen($bin); for ($i = 1; $i <= $pad; $i++) { $bin = "0".$bin; } } $bits = 0; while ($bits <= 7) { $bin_part = substr($bin,($bits*16),16); $ipv6 .= dechex(bindec($bin_part)).":"; $bits++; } // compress return inet_ntop(inet_pton(substr($ipv6,0,-1))); } print $ipv6long = ip2long6($ipv6)."\n"; print $ipv6 = long2ip6($ipv6long)."\n"; ?> I got it from here: http://www.php.net/m...2long.php#94477 . (I have enabled gmp-lib.) I'm guessing that I should find a different function. Edited November 19, 2012 by dannon Quote Link to comment Share on other sites More sharing options...
dannon Posted November 19, 2012 Author Share Posted November 19, 2012 Oh wait. Will the ip2long6 work for IPv4? I'm so confused right now. I'm going to sleep, I need to rebuild my blown up brain. Hopefully we will get it working tomorrow. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.