Curl issue

Hi everyone, just would like to ask if anyone could assist in this …
below script was left abandoned and i am not good in curl. From what i was told, when it goes to the site without extension of .mp3, curl will only start and it will go to the page with the download being triggered.


// Check needed parameter
if ( !( isset( $_GET["id"] ) && is_numeric( $_GET["id"] ) && ( $index = (int)$_GET["id"] ) ) ){
// Include scripts
include( "scripts/options.php" );
include( "scripts/main.php" );
$arr = array("mp3");
if ( $song = new Song( $index ) ){
	var_dump( $song );
	if ( $song->index ){
		$arr1 = explode(".",$song->url);
		$ext = $arr1[count($arr1)-1];
			header( "Location: $song->url" );	
			$ch = curl_init();
			$timeout = 5;
			curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0");
			curl_setopt($ch, CURLOPT_URL, $song->url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
			curl_setopt($ch, CURLOPT_HEADER, false);
			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
			curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
			$data = curl_exec($ch);
			$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
			$arr_last = explode("?",$last_url);
			echo $last_url = $arr_last[0];
			$arr1 = explode(".",$last_url);
			$ext = $arr1[count($arr1)-1];
				header( "Location: $song->url" );	
				echo $data;

From the downloadagent.php, when i check the source code…it shows this…

object(Song)#1 (5) {
  string(34) "Eyes On The Money (Prod. Sdotfire)"
  string(45) ""

but still, the page wont load properly… is there anything missed out from the code ?
kindly advise.

Many thanks

“CURLOPT_VERBOSE” you can use this debugging function in your code to know where the error is!