|
|
@@ -0,0 +1,39 @@
|
|
|
+<?php
|
|
|
+function generateHash($macAddress, $timestamp, $customString) {
|
|
|
+ // 组合输入字符串
|
|
|
+ $inputString = $macAddress . $timestamp . $customString;
|
|
|
+
|
|
|
+ // 使用SHA256进行加密
|
|
|
+ $hash = hash('sha256', $inputString);
|
|
|
+
|
|
|
+ return $hash;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+$headers = getallheaders();
|
|
|
+
|
|
|
+
|
|
|
+//有一个不存在就判断异常
|
|
|
+if(!isset($headers['X-Special-Header'])||isset($headers['Timestamp'])||isset($headers['Clinet-Mac'])){
|
|
|
+ die("非法访问");
|
|
|
+}
|
|
|
+//foreach ($headers as $name => $value) {
|
|
|
+// echo "$name: $value<br>";
|
|
|
+//}
|
|
|
+
|
|
|
+
|
|
|
+//X-Special-Header token 字段 ='sha256' (Mac+时间戳+自定义字符串)
|
|
|
+//Timestamp 时间戳
|
|
|
+//Clinet-Mac mac地址
|
|
|
+
|
|
|
+//10秒内可以访问
|
|
|
+if((time()-$headers['Timestamp'])<10){
|
|
|
+ die("无效访问");
|
|
|
+}
|
|
|
+if(generateHash($headers['Clinet-Mac'],$headers['Timestamp'],"minong123")!=$headers['X-Special-Header']){
|
|
|
+ die("非法访问");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+?>
|