Google cannot be opened in China. Many of my friends will find a way to set up a hosts specified IP address, which can still be accessed normally. Next we will introduce you to a php program for capturing googlehosts, I hope it will be useful to you. google cannot be opened in China. Many of my friends will find a way to set up a hosts specified IP address, which can still be accessed normally. Next we will introduce you to a php program for capturing google hosts, I hope it will be useful to you.
Script ec (2); script
Bored, I found another php version to capture the google hosts file. I tried it and tried it again. I pinged the ip address, and the latency was not very high, the web page is opened and tested quickly. If you are interested, try it.
PHP file:
/**
* Google
* @ Author: Self-entertainment
* Date: 2015/2/6
* Time: 11: 42
*/
Define ('start _ tag', '# google-hosts-2015 ');
Define ('end _ tag', '# google-hosts-2015-end ');
If (! Empty ($ argv [1]) {
$ Params = array ();
Parse_str ($ argv [1], $ params );
If (isset ($ params ['url']) {
Define ('Google _ HOST_URL ', $ params ['url']);
}
If (isset ($ params ['del ']) {
Define ('delete _ GOOGLE_HOST ', true );
}
}
Defined ('Google _ HOST_URL ') | define ('Google _ HOST_URL', 'HTTP: // www.360kb.com/kb/2_150.html ');
If (PHP_ OS = 'winnt '){
Define ('hosts _ FILE_PATH ', 'c: WindowsSystem32driversetchosts ');
} Else if (in_array (PHP_ OS, array ('linux ', 'darwin', 'freebsd', 'opensd', 'win32 ', 'windows', 'unix '))) {
Define ('hosts _ FILE_PATH ','/etc/hosts ');
} Else {
Die ('unsupported system! '. PHP_EOL );
}
If (! Is_writable (HOSTS_FILE_PATH )){
Die ('without permission, please use the root user to perform! '. PHP_EOL );
}
$ Hosts = file_get_contents (HOSTS_FILE_PATH );
$ StartPos = strpos ($ hosts, START_TAG );
If (! Defined ('delete _ GOOGLE_HOST ')){
$ Gs = get_google_hosts ();
Echo GOOGLE_HOST_URL.PHP_EOL;
Echo $ gs. PHP_EOL;
} Else {
$ Gs = '';
Echo 'reset hosts'. PHP_EOL;
}
If ($ startPos ){
$ _ Tmp = substr ($ hosts, $ startPos, strpos ($ hosts, END_TAG)-$ startPos + strlen (END_TAG ));
$ Hosts = str_replace ($ _ tmp, $ gs, $ hosts );
} Else {
$ Hosts. = PHP_EOL. $ gs;
}
$ Old_file_size = filesize (HOSTS_FILE_PATH );
If (file_put_contents (HOSTS_FILE_PATH, $ hosts )){
Die ('success. '. PHP_EOL );
} Else {
Die ('fail '. PHP_EOL );
}
Function get_google_hosts (){
$ Html = file_get_contents (GOOGLE_HOST_URL );
$ Html = strip_tags ($ html );
$ StartPos = strpos ($ html, START_TAG );
$ Html = substr ($ html, $ startPos, strpos ($ html, END_TAG)-$ startPos );
$ Html = str_replace ('','', $ html );
Return $ html. PHP_EOL.END_TAG;
}