Skip to content

Instantly share code, notes, and snippets.

@easychen
Last active July 16, 2017 06:29
Show Gist options
  • Save easychen/a8de35c6ce3ff191381940d089655f32 to your computer and use it in GitHub Desktop.
Save easychen/a8de35c6ce3ff191381940d089655f32 to your computer and use it in GitHub Desktop.
获取url对应的302跳转地址
<?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