SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Curl issue

  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    <<<<<downloadagent.php>
    Code:
    <?php
    // Check needed parameter
    if ( !( isset( $_GET["id"] ) && is_numeric( $_GET["id"] ) && ( $index = (int)$_GET["id"] ) ) ){
    	exit();
    }
    // Include scripts
    include( "scripts/options.php" );
    include( "scripts/main.php" );
    $arr = array("mp3");
    if ( $song = new Song( $index ) ){
    	var_dump( $song );
    	if ( $song->index ){
    		$song->downloads++;
    		$song->update();
    		$arr1 = explode(".",$song->url);
    		$ext = $arr1[count($arr1)-1];
    		if(in_array($ext,$arr)){		
    			header( "Location: $song->url" );	
    		}else{
    			$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];
    			curl_close($ch);
    			$arr1 = explode(".",$last_url);
    			$ext = $arr1[count($arr1)-1];
    			if(in_array($ext,$arr)){		
    				header( "Location: $song->url" );	
    			}else{
    				echo $data;
    			}
    		}
    	}
    }
    ?>


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

    Code:
    object(Song)#1 (5) {
      ["index"]=>
      int(163)
      ["name"]=>
      string(34) "Eyes On The Money (Prod. Sdotfire)"
      ["url"]=>
      string(45) "http://www.hulkshare.com/dl/a5dfciq2eoxm/?d=1"
      ["downloads"]=>
      int(11)
      ["length"]=>
      int(0)
    }


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

    Many thanks

  2. #2
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "CURLOPT_VERBOSE" you can use this debugging function in your code to know where the error is!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •