Hi all, I'm developing a site relating to YouTube videos. I currently have a function that retrieves the YouTube FLV URL. For example: http://www.youtube.com/get_video?video_id=XC71t8GzqPs&t=OEgsToPDskJtI1jb1nE9xx9Ia-RxuCoh However, this URL redirects to another URL that is the true location of the video file. For example, the above URL redirects to: http://lax-v158.lax.youtube.com/get_video?video_id=XC71t8GzqPs My Flash applet does not work if the function returns the non-redirected URL. Is there any way to make a function that follows the first URL and returns the true location of the video file (the second URL)? Thanks in advance for any help.
function getRedirect($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); preg_match("/Location: (.*?)\n/", $result, $match); $realurl = $match[1]; return $realurl; } PHP: That should work.