array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'function.ip2long.php', 1 => 'ip2long', ), 'up' => array ( 0 => 'ref.network.php', 1 => 'Ağ İşlevleri', ), 'prev' => array ( 0 => 'function.inet-pton.php', 1 => 'inet_pton', ), 'next' => array ( 0 => 'function.long2ip.php', 1 => 'long2ip', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'tr', 'path' => 'reference/network/functions/ip2long.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
ip2long — Noktalı IP adresi gösterimini içeren bir dizgeyi uzun tamsayıya dönüştürür
ip2long() işlevi bir IPv4 adresin noktalı gösterimini kullanarak uzun tamsayı gösterimini üretir.
ip2long() işlevi ayrıca, tamamı belirtilmemiş IP adresleri ile de çalışır. Daha fazla bilgi için » http://ps-2.kev009.com/wisclibrary/aix52/usr/share/man/info/en_US/a_doc_lib/libs/commtrf2/inet_addr.htm adresine bakınız.
ip
Noktalı gösterimle bir IPv4 adresi.
Belirtilen ip
geçirsizse false
, aksi
takdirde uzun tamsayı ile döner
Örnek 1 - ip2long() Örneği
<?php
$ip = gethostbyname('localhost');
$out = "Bu adresler aynıdır:<br />\n";
$out .= 'http://localhost/, http://' . $ip . '/ ve http://' .
sprintf("%u", ip2long($ip)) . "/<br />\n";
echo $out;
?>
Örnek 2 - Bir IP adresinin gösterilmesi
Bu örnekte, printf() işleviyle dönüştürülmüş bir adresin nasıl basılacağı gösterilmiştir:
<?php
$ip = gethostbyname('mesela.dom');
$long = ip2long($ip);
if ($long == -1 || $long === FALSE) {
echo 'IP geçersiz, tekrar deneyin';
} else {
echo $ip . "\n"; // 192.0.34.166
echo $long . "\n"; // 3221234342 (32-bit sistemlerde tamsayı taşması sebebiyle -1073732954)
printf("%u\n", ip2long($ip)); // 3221234342
}
?>
Bilginize:
PHP'nin int türü işaretli tamsayı olduğundan ve çoğu IP adresi 32 bitlik sistemlerde negatif tamsayılarla sonuçlanacağından işaretsiz tamsayı IP adresinin dizge gösterimini elde etmek için sprintf() ve printf() işlevlerinde %u değiştiricisini kullanmalısınız.
Bilginize:
ip2long() işlevi 32 bitlik sistemlerde
255.255.255.255
IP adresi için tamsayı taşması sebebiyle-1
döndürür.