11.php 924 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. function generateHash($macAddress, $timestamp, $customString) {
  3. // 组合输入字符串
  4. $inputString = $macAddress . $timestamp . $customString;
  5. // 使用SHA256进行加密
  6. $hash = hash('sha256', $inputString);
  7. return $hash;
  8. }
  9. $headers = getallheaders();
  10. //有一个不存在就判断异常
  11. if(!isset($headers['X-Special-Header'])||isset($headers['Timestamp'])||isset($headers['Clinet-Mac'])){
  12. die("非法访问");
  13. }
  14. //foreach ($headers as $name => $value) {
  15. // echo "$name: $value<br>";
  16. //}
  17. //X-Special-Header token 字段 ='sha256' (Mac+时间戳+自定义字符串)
  18. //Timestamp 时间戳
  19. //Clinet-Mac mac地址
  20. //10秒内可以访问
  21. if((time()-$headers['Timestamp'])<10){
  22. die("无效访问");
  23. }
  24. if(generateHash($headers['Clinet-Mac'],$headers['Timestamp'],"minong123")!=$headers['X-Special-Header']){
  25. die("非法访问");
  26. }
  27. ?>