unshorten.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. ini_set("display_errors",1);
  3. error_reporting(E_ALL);
  4. $config = parse_ini_file('config/config.ini',true);
  5. function checkCode($config,$url) {
  6. if(in_array('curl',get_loaded_extensions())) {
  7. $ch = curl_init($url);
  8. curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0');
  9. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  10. curl_setopt($ch,CURLOPT_NOBODY,true);
  11. if($config["Proxy"]["type"]) {
  12. curl_setopt($ch,CURLOPT_PROXY,$config["Proxy"]["type"]."://".$config["Proxy"]["domain"].":".$config["Proxy"]["port"]);
  13. curl_setopt($ch,CURLOPT_PROXYUSERPWD,$config["Proxy"]["username"].":".$config["Proxy"]["password"]);
  14. }
  15. curl_exec($ch);
  16. $httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
  17. curl_close($ch);
  18. if($httpcode == 301 || $httpcode == 302) return checkRedirect($config,$url);
  19. else return $url;
  20. }
  21. else return $url;
  22. }
  23. function checkRedirect($config,$url) {
  24. $ch = curl_init($_GET['url']);
  25. curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0');
  26. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  27. curl_setopt($ch,CURLOPT_NOBODY,true);
  28. if($config["Proxy"]["type"]) {
  29. curl_setopt($ch,CURLOPT_PROXY,$config["Proxy"]["type"]."://".$config["Proxy"]["domain"].":".$config["Proxy"]["port"]);
  30. curl_setopt($ch,CURLOPT_PROXYUSERPWD,$config["Proxy"]["username"].":".$config["Proxy"]["password"]);
  31. }
  32. curl_exec($ch);
  33. $redirect = curl_getinfo($ch,CURLINFO_REDIRECT_URL);
  34. if(isset($redirect) && !empty($redirect)) return checkCode($config,$redirect);
  35. else return $url;
  36. }
  37. echo checkCode($config,$_GET['url']);
  38. ?>