Jump to content

Ipv6 Broke My Site


dannon

Recommended Posts

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?

Link to comment
Share on other sites

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 by berridgeab
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by dannon
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.