Home  >  Article  >  Backend Development  >  Windows下PHP修改Hosts文件的方法

Windows下PHP修改Hosts文件的方法

WBOY
WBOYOriginal
2016-06-23 13:57:42985browse

通过PHP程序完成修改Hosts文件原理如下:

1,Neil没有找到直接利用PHP修改的方法,所以首先是写一个.bat文件

2,使用system(),调用.bat完成修改Hosts的目的


代码如下:

//创建.bat$filename = "updata.bat";
//'@echo 127.0.0.1 baidu.com >>C:\Windows\System32\Drivers\etc\hosts 关于.bat中的内容可以参考DOS命令行file_put_contents($filename,'@echo 127.0.0.1 baidu.com >>C:\Windows\System32\Drivers\etc\hosts');system($filename);

上述代码 完成了向Hosts文件末尾插入 127.0.0.1    baidu.com 这一行

至于其他的操作可以看看DOS命令行,这里我主要是为大家提供一个思路,关于linux下的还在研究中。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn