Php code for querying links on the homepage

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
/*
* Querying external links on the homepage hyperlink Lookup
* Lost63.com original QQ: 35501547
* Indicate the source for reprinting.
*/

If ($ _ GET ['action'] = "check "){

$ Domain = $ _ POST ['domain '];

// If the domain name form item is blank, the address bar parameters are obtained.
If ($ domain = ""){
$ Domain = $ _ GET ['domain '];
}

// URL
$ Url = "http: //". $ domain;

// Read the webpage and return the webpage source file content
Function read_url ($ str ){

$ File = fopen ($ str, "r") or die ($ str. '-> An error occurred while reading the remote URL! <A href = "? Next = '. ($ _ GET ['Next'] + 1 ). '& action = check & domain = '. $ _ GET ['domain ']. '"> click to continue query </a> <br> ');
While (! Feof ($ file )){
$ Result. = fgets ($ file, 9999 );
}
Fclose ($ file );
Return $ result;

}

// Open the session
Session_start ();

// If $ _ SESSION ['matches'] is not assigned a value, set it;
If (! Isset ($ _ SESSION ['matches']) {
$ Result = read_url ($ url );

Preg_match_all ('/<(.*?) Href = "(http :\/\/.*?) "(. *?)> (.*?) <\/A>/I ', $ result, $ matches );
$ Num = count ($ matches [2]);
For ($ I = 0; $ I <$ num; $ I ++ ){
If (strpos ($ matches [2] [$ I], $ domain)> 0 ){
Unset ($ matches [2] [$ I]);
}
}

$ _ SESSION ['matches'] = $ matches [2];
}
// Retrieve the URL array from the session directly;
$ Matches [2] =_ _ SESSION ['matches'];

$ N = count ($ matches [2]);

$ Next = 0;
$ Next + = $ _ GET ['Next'];

$ Result = read_url ($ matches [2] [$ next]);

If (strpos ($ result, $ domain)> 0 ){
$ Value = $ matches [2] [$ next]. '<font color = green> true </font> <br> ';
} Else {
$ Value = $ matches [2] [$ next]. '<font color = red> false </font> <br> ';
}
$ Values = $ _ COOKIE ['check _ result']. $ value;
Setcookie ("check_result", $ values, time () + 3600 );
Echo $ values;

If ($ next = $ n ){
Echo "Scan completed! ";
} Else {
Echo '<meta http-equiv = "refresh" content = "1; URL =? Next = '. ($ next + 1).' & action = check & domain = '. $ domain.' "/> ';
}


} Else {
// Delete cookies
Setcookie ("check_result", "", time ()-3600 );
Echo '<form name = "form1" method = "post" action = "? Action = check ">
<Input type = "text" name = "domain">
<Input type = "submit" name = "Submit" value = "submit">
<Font color = "red"> * </font> enter a domain name, for example, jb51.net.
</Form> ';
}
?>

Related Article

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.