Rumah > pembangunan bahagian belakang > tutorial php > php ip地址转换整数,整数转换地址

php ip地址转换整数,整数转换地址

WBOY
Lepaskan: 2016-07-29 09:09:44
asal
1729 orang telah melayarinya

<code><span>$ipArr</span>    = explode(<span>'.'</span>,<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]);



     <span>$ipVal</span> = <span>$ipArr</span>[<span>0</span>] * <span>0x1000000</span>
            + <span>$ipArr</span>[<span>1</span>] * <span>0x10000</span>
            + <span>$ipArr</span>[<span>2</span>] * <span>0x100</span>
            + <span>$ipArr</span>[<span>3</span>]
            ;

        <span>echo</span><span>$ipVal</span>.<span>'<br>'</span>;

         <span>$ipArr</span> = <span>array</span>(<span>0</span> => floor( <span>$ipVal</span>/ <span>0x1000000</span>) );

        <span>$ipVint</span>   = <span>$ipVal</span>-(<span>$ipArr</span>[<span>0</span>]*<span>0x1000000</span>); <span>// for clarity</span><span>$ipArr</span>[<span>1</span>] = (<span>$ipVint</span> & <span>0xFF0000</span>)  >> <span>16</span>;

        <span>$ipArr</span>[<span>2</span>] = (<span>$ipVint</span> & <span>0xFF00</span>  )  >> <span>8</span>;

        <span>$ipArr</span>[<span>3</span>] =  <span>$ipVint</span> & <span>0xFF</span>;

        <span>$ipDotted</span> = implode(<span>'.'</span>, <span>$ipArr</span>);

        <span>echo</span><span>$ipDotted</span>;















<span><?php </span><span>$ipArr</span>    = explode(<span>'.'</span>,<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]);
  <span>$ip</span>       = <span>$ipArr</span>[<span>0</span>] * <span>0x1000000</span>
            + <span>$ipArr</span>[<span>1</span>] * <span>0x10000</span>
            + <span>$ipArr</span>[<span>2</span>] * <span>0x100</span>
            + <span>$ipArr</span>[<span>3</span>]
            ;
<span>?></span>This can be written in a bit more efficient way:
<span><?php </span><span>$ipArr</span>    = explode(<span>'.'</span>,<span>$_SERVER</span>[<span>'REMOTE_ADDR'</span>]);
  <span>$ip</span>       = <span>$ipArr</span>[<span>0</span>]24</span>
            + <span>$ipArr</span>[<span>1</span>]16</span>
            + <span>$ipArr</span>[<span>2</span>] 8
            + <span>$ipArr</span>[<span>3</span>]
            ;
<span>?></span>shift is more cheaper.</code>
Salin selepas log masuk
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了php ip地址转换整数,整数转换地址,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan