PHP sebagai bahasa pemrograman modular telah dilengkapi dengan kemampuan-kemampuan dasar networking (deteksi dan pengelolaan jaringan). Fungsi-fungsi bawaan ini hanya memerlukan aplikasi Bind di Linux, khusus untuk fungsi checkdnsrr(), getmxrr() dan dns_get_record().
Berikut adalah fungsi-fungsi networking PHP yang bisa anda manfaatkan:
1. checkdnsrr()
fungsi ini digunakan untuk mendapatkan nilai boolean DNS dari sebuah hostname atau IP Address. Jika ada maka bernilai TRUE, jika tidak ada maka bernilai FALSE.
2. dns_get_record()
fungsi ini digunakan untuk mendapatkan nama server DNS dari sebuah host /alamat web. Pola penggunaan:
[sourcecode language=”php”]
array dns_get_record ( string $hostname [, int $type = DNS_ANY [, array &$authns [, array &$addtl ]]] )
[/sourcecode]
contoh:
[sourcecode language=”php”]
<?php
$result = dns_get_record("php.net");
print_r($result);
?>
[/sourcecode]
hasil:
[sourcecode]
Array
(
[0] => Array
(
[host] => php.net
[type] => MX
[pri] => 5
[target] => pair2.php.net
[class] => IN
[ttl] => 6765
)
[1] => Array
(
[host] => php.net
[type] => A
[ip] => 64.246.30.37
[class] => IN
[ttl] => 8125
)
)
[/sourcecode]
3. gethostbyaddr()
fungsi untuk mengetahui nama host (hostname) dari sebuah IP Address. Pola penggunaan:
[sourcecode language=”php”]
string gethostbyaddr ( string $ip_address )
[/sourcecode]
contoh:
[sourcecode language=”php”]
<?php
echo gethostbyaddr(‘118.97.9.48’);
?>
[/sourcecode]
hasil:
[sourcecode]
48.subnet118-97-9.astinet.telkom.net.id
[/sourcecode]
4. ip2long
adalah fungsi untuk mengkonversi string yang mengandung alamat IP Address versi 4 (IPv4) ke dalam alamat tertentu berbentuk integer. Pola penggunaan:
[sourcecode language=”php”]
int ip2long ( string $ip_address )
[/sourcecode]
Contoh:
[sourcecode language=”php”]
<?php
echo ip2long(‘118.97.9.48’);
?>
[/sourcecode]
Hasil:
[sourcecode]
1986070832
[/sourcecode]
5. long2ip()
adalah fungsi kebalikan dari fungsi ip2long(), dimana fungsi ini akan mengkonversi sebuah nilai integer bawaan PHP ke dalam alamat IP versi 4 (IPv4). Pola penggunaan:
[sourcecode language=”php”]
string long2ip ( string $proper_address )
[/sourcecode]
Contoh:
[sourcecode language=”php”]
<?php
echo long2ip(‘1986070832’);
?>
[/sourcecode]
Hasil:
[sourcecode]
118.97.9.48
[/sourcecode]
Itulah 5 diantara beberapa fungsi-fungsi networking bawaan PHP. Semoga berguna. Silakan baca lebih lanjut dokumentasi PHP dibagian Other Services.
Salam,
Comments are closed.