test.php 623 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: chendeben
  5. * Date: 2019-01-11
  6. * Time: 17:41
  7. */
  8. echo getRealUrl($_GET['url']);
  9. function getRealUrl($url)
  10. {
  11. //得到百度跳转的真正地址
  12. $header = get_headers($url, 1);
  13. if (strpos($header[0], '301') || strpos($header[0], '302')) {
  14. if (is_array($header['Location'])) {
  15. //return $header['Location'][count($header['Location'])-1];
  16. $_url = $header['Location'][0];
  17. } else {
  18. $_url = $header['Location'];
  19. }
  20. } else {
  21. $_url = $url;
  22. }
  23. $url = parse_url($_url);
  24. return $url['host'];
  25. }