Last active
July 16, 2017 06:29
-
-
Save easychen/a8de35c6ce3ff191381940d089655f32 to your computer and use it in GitHub Desktop.
获取url对应的302跳转地址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_302_location( $url ) | |
{ | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
$output = curl_exec($ch); | |
curl_close($ch); | |
$reg2 = '/Location:\s(.+?)\r/is'; | |
if( preg_match( $reg2 , $output , $out2 ) ) | |
return trim($out2[1]); | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment