php抓資料存成檔案

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

$schcidr="192.168.0.0/16";
$ip=$_SERVER["REMOTE_ADDR"];

function ($ip, $range){
list ($subnet, $bits) = explode('/', $range);
if ($bits === null) {
$bits = 32;
}
$ip = ip2long($ip);
$subnet = ip2long($subnet);
$mask = -1 << (32 - $bits);
$subnet &= $mask; # nb: in case the supplied subnet wasn't correctly aligned
return ($ip & $mask) == $subnet;
}
//檢查為 內網 或是 在主機端直接執行
if(cidr_match($ip, $schcidr) or empty($ip)){
$fname = "/u/www/travel/b2c/addfile/citytest/".date('Y-m-d').".html";
//開啟檔案,若檔案不存在則會試著建立
$fd=fopen($fname,"w");
fwrite($fd,$showdata);
fclose($fd);
//檢查 檔案存在 且 權限不是646 時執行權限設定
if(file_exists($fname) && substr(decoct(fileperms($fname)), 2) != '0646')
chmod($fname, 0646);
}
?>