proxy.php 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require_once __DIR__ . '/include/config.php';
  3. if (
  4. !isset($_GET['dest'])
  5. || !(
  6. strpos($_GET['dest'], 'i.pximg.net/') === 0
  7. || strpos($_GET['dest'], 's.pximg.net/') === 0
  8. )
  9. ) {
  10. http_response_code(400);
  11. die('Illegal request');
  12. }
  13. $stream_context = [
  14. 'http' => [
  15. 'header' =>
  16. "User-Agent: Mozilla/5.0" . PHP_EOL .
  17. 'Referer: https://www.pixiv.net/'
  18. ]
  19. ];
  20. if (HTTP_PROXY) {
  21. $stream_context['http']['proxy'] = 'tcp://' . HTTP_PROXY;
  22. }
  23. $response = file_get_contents('https://' . $_GET['dest'], false, stream_context_create($stream_context));
  24. if (!$response) {
  25. http_response_code(500);
  26. die('Proxy failed');
  27. }
  28. foreach ($http_response_header as $header) {
  29. if (strpos($header, 'Content-Type: ') === 0) {
  30. header($header);
  31. break;
  32. }
  33. }
  34. $path = explode('/', $_GET['dest']);
  35. header('Content-Disposition: filename="' . $path[count($path) - 1] . '"');
  36. echo $response;