index.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. $host = $_SERVER['SERVER_NAME'];
  3. $szUrl = $_GET['url'];
  4. $baseUrl = explode('/',$szUrl);
  5. if($baseUrl[0] == 'http:' || $baseUrl[0] == 'https:'){
  6. $baseUrl = '//'.$host.'?url='.$baseUrl[2];
  7. }else{
  8. $baseUrl = '//'.$host.'?url='.$baseUrl[0];
  9. }
  10. $UserAgent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 3.5.21022; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
  11. $curl = curl_init();
  12. curl_setopt($curl, CURLOPT_URL, $szUrl);
  13. curl_setopt($curl, CURLOPT_HEADER, 1); //0表示不输出Header,1表示输出
  14. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  15. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  16. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  17. curl_setopt($curl, CURLOPT_ENCODING, '');
  18. curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
  19. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  20. $data = curl_exec($curl);
  21. $i_headerLen = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  22. $s_header = substr($data,0, $i_headerLen);
  23. $s_body = substr($data, $i_headerLen);
  24. $pos = substr($s_header,strpos($s_header,'Content-Type'));
  25. $content_type = explode(" ",$pos );
  26. //正则替换
  27. $regex4 = "/src=\"https:\/\/(.*\/.*?)\"/";;
  28. $replace4 = "src=https://$host?url=$1";
  29. $html = preg_replace($regex4,$replace4,$s_body);
  30. $regex5 = "/href=\"https:\/\/(.*\/.*?)/";;
  31. $replace5 = "href=\"https://$host?url=$1";
  32. $html = preg_replace($regex5,$replace5,$html);
  33. $regex6 = "/data-original=\"https:\/\/(.*\/.*?)/";;
  34. $replace6 = "data-original=\"https://$host?url=$1";
  35. $html = preg_replace($regex6,$replace6,$html);
  36. $regex7 = "/src=\"http:\/\/(.*\/.*?)\"/";;
  37. $replace7 = "src=https://$host?url=$1";
  38. $html = preg_replace($regex7,$replace7,$html);
  39. $regex8 = "/href=\"http:\/\/(.*\/.*?)/";;
  40. $replace8 = "href=\"https://$host?url=$1";
  41. $html = preg_replace($regex8,$replace8,$html);
  42. $regex9 = "/data-original=\"http:\/\/(.*\/.*?)/";;
  43. $replace9 = "data-original=\"https://$host?url=$1";
  44. $html = preg_replace($regex9,$replace9,$html);
  45. $regex = "/src=\"\/(.*\/.*?)\"/";;
  46. $replace = "src=$baseUrl/$1";
  47. $html = preg_replace($regex,$replace,$html);
  48. $regex2 = "/href=\"\/(.*\/.*?)/";;
  49. $replace2 = "href=\"$baseUrl/$1";
  50. $html = preg_replace($regex2,$replace2,$html);
  51. $regex3 = "/data-original=\"\/(.*\/.*?)/";;
  52. $replace3 = "data-original=\"$baseUrl/$1";
  53. $html = preg_replace($regex3,$replace3,$html);
  54. //echo curl_errno($curl); //返回0时表示程序执行成功 如何从curl_errno返回值获取错误信息
  55. header($content_type[0]);
  56. echo $html;