PHP website with IP query Code _php tutorial

Source: Internet
Author: User
Tags php website domain name registration
This section of the source code is a PHP web site with IP query codes Oh, if you like to come in and see it.

if (function_exists (' Date_default_timezone_set ')) {
Date_default_timezone_set (' Asia/shanghai '); Set time zone
}
Define ("App_root", DirName (DirName (__file__))); Site root directory

function Visitorip () {//Visitor IP
if ($_server[' http_x_forwarded_for ']) {
$ipa = $_server[' http_x_forwarded_for ');
}elseif ($_server[' http_client_ip ']) {
$ipa = $_server[' http_client_ip ');
}else{
$ipa = $_server[' remote_addr ');
}
return $IPA;
}

function Cleandomain ($q, $w =0) {//organize domain name $w = 1 Filter www. prefix $w =0 not filtered
$q = Htmlspecialchars (Strtolower (Trim ($q)));
if (substr ($q, 0,7) = = "/http" | | substr ($Q, 0,8) = = "https://" | | substr ($Q, 0,6) = = "ftp://") {
$q = Str_replace ("http:/", "", $q);
$q = Str_replace ("https:/", "", $q);
$q = Str_replace ("ftp:/", "", $q);
}
if (substr ($q, 0,4) = = "www." && $w ==1) {
$q = Str_replace ("www.", "", $q);
}
$q = Trim ($q, "/");
return $q;
}

Get Web page
Class HttpRequest
{
/*
Get Web page
*/
var $_fp; HTTP socket
var $_url; Full URL
var $_host; HTTP Host
var $_protocol; Protocol (HTTP/HTTPS)
var $_uri; Request URI
var $_port; Port

Scan URL
function _scan_url ()
{
$req = $this->_url;

$pos = Strpos ($req, '://');
$this->_protocol = Strtolower (substr ($req, 0, $pos));

$req = substr ($req, $pos +3);
$pos = Strpos ($req, '/');
if ($pos = = = False)
$pos = strlen ($req);
$host = substr ($req, 0, $pos);

if (Strpos ($host, ': ')!== false)
{
List ($this->_host, $this->_port) = Explode (': ', $host);
}
Else
{
$this->_host = $host;
$this->_port = ($this->_protocol = = ' https ')? 443:80;
}

$this->_uri = substr ($req, $pos);
if ($this->_uri = = ")
$this->_uri = '/';
}

Constructor
function HttpRequest ($url)
{
$this->_url = $url;
$this->_scan_url ();
}

Download URL to String
function downloadtostring ()
{
$crlf = "RN";
$response = "";
Generate request
$req = ' GET '. $this->_uri. ' http/1.0 '. $crlf
. ' Host: '. $this->_host. $crlf
. $crlf;

Fetch
$this->_fp = @fsockopen ($this->_protocol = = ' https '? ' ssl://': '). $this->_host, $this->_port);
@fwrite ($this->_fp, $req);
while (Is_resource ($this->_fp) && $this->_fp &&!feof ($this->_fp))
$response. = Fread ($this->_fp, 1024);
@fclose ($this->_fp);

Split header and body
$pos = Strpos ($response, $crlf. $crlf);
if ($pos = = = False)
return ($response);
$header = substr ($response, 0, $pos);
$body = substr ($response, $pos + 2 * strlen ($CRLF));

Parse headers
$headers = Array ();
$lines = Explode ($crlf, $header);
foreach ($lines as $line)
if ($pos = Strpos ($line, ': '))!== false)
$headers [Strtolower (Trim (substr ($line, 0, $pos))] = Trim (substr ($line, $pos + 1));

Redirection?
if (Isset ($headers [' location ')])
{
$http = new HttpRequest ($headers [' location ']);
Return ($http->downloadtostring ($http));
}
Else
{
return ($body);
}
}
}

function get_html ($siteurl) {
Save page code to a string
$r =new HttpRequest ($siteurl);
$htm = $r->downloadtostring ();
return $htm;
}

$visitorip = Visitorip ();

$q = Cleandomain ($_post[' Q ');
$q _encode = UrlEncode ($q);

$title = "Query with IP site";

$chaxun _status = 0; Query status-1 is no query parameters, 0 is the query error, 1 is the domain name, 2 is to check the IP

if (Isset ($_get[' action ')) && trim ($_get[' action ') = = = "Do") {//ajax Bring up data
$IPARR = Reverseip ($q);
if (count ($IPARR) >0) {
Echo '

This IP found '. COUNT ($IPARR). ' Domain name, see below:

';
Echo '
      ';
      for ($i =0; $i<>
      Echo '
    • '. $IPARR [$i]. '
    • ';
      }
      Echo '
';
}else{
Echo '

No IP '. $ip. ' corresponding domain name record!

';
}
Die ();
}

function Iptoint ($Ip) {//IP converted to Digital
$array =explode ('. ', $Ip);
$Int = ($array [0] * 256*256*256) + ($array [1]*256*256) + ($array [2]*256) + $array [3];
return $Int;
}

function Reverseip ($q) {
$htm = get_html (' http://www.ip-adress.com/reverse_ip/'. $q);
Preg_match_all ('/whois/', $htm, $TT);
$res = $tt [1];
return $res;
}

if (Preg_match ("/[a-za-z-_]+/si", $q)) {//If the query is a domain name
$ip = gethostbyname ($q);
if ($ip = = $q) {
$ip = $visitorip;
$chaxun _status =-1;
}else{
$chaxun _status = 1;
}
}elseif (Ereg ("^[0-9]{1,3}.[ 0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}$ ", $q)) {//If the query is IP
$ip = $q;
$chaxun _status = 2;
}else{
$ip = $visitorip;
}
?>



<title>same IP site query</title>

0) {?>







Webmaster Tools > Query with IP site Bookmark this page









same IP site query








Enter the domain name or IP address and which sites are available on the server that queries the same IP address.








if ($chaxun _status==1) {
Echo '. $title. ' > Domain: '. $q;
}elseif ($chaxun _status==2) {
Echo '. $title. ' > IP: ' $ip;
}else{
echo $title;
}
?>



if (! $q) {
$IPQ = ' Your IP address is:'. $ip. ';
}elseif ($chaxun _status = = 0) {
$IPQ = ' wrong! did not find a match with '. $q. ' , determine if the format of the ip/domain is written!

Your IP address is: '. $ip;
}elseif ($chaxun _status==1) {
$IPQ = ' The domain name you queried '. $q. '

IP of the domain name: '. $ip. ';
}else{
$IPQ = "IP you queried:". $ip;
}
Echo $IPQ;
?>

0) {?>

Related query: Alexa query | Domain Name Registration Enquiry | Whois Query | IP Address Query | PR Enquiry | Weather Forecast Query | Imitation Spider | Friendship link Query







The Webmaster Tools


Download package with IP query code


http://www.bkjia.com/PHPjc/445038.html www.bkjia.com true http://www.bkjia.com/PHPjc/445038.html techarticle This section of the source code is a PHP web site with IP query codes Oh, if you like to come in and see it.? php if (function_exists (' Date_default_timezone_set ')) {Date_default_ Timezone_set (' Asia/sha ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.