Jump to content

Stay on a site and download a file using curl and php


lordphate

Recommended Posts

Okay the title may be confusing...

 

I'm trying to download a file from a site [they offer the download for free]. however i get a 403 error when trying to use curl or fsocketopen. after ALOT of trial and error i found out that you must be actively on the site to be able to download the file.. Is there a way to do this using curl or fsocketopen?

 

I'll post what i have right now

 

	$curl = curl_init($reffer); 
	curl_setopt($curl, CURLOPT_URL,$reffer); 
	curl_setopt($curl, CURLOPT_USERAGENT, $agent); 
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
	$store = curl_exec ($curl);
	curl_setopt($curl, CURLOPT_URL,$values["video"]);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
	$flv = curl_exec($curl);
	print($flv);exit;		
	fwrite($flash,$flv);
	fclose($flash);

    curl_close($curl);

Considering your script hinted that you're trying to download a video, and the remote site obviously doesn't want you to do so, I'm kind of hesitant to help you, but you'll probably be helped anyway, so I might as well, I guess.

 

 

It probably uses cookies or user-agent validation.  Most likely it just has a session going or something, meaning you would ned to setup cookie stuff.

Corbin,

 

I've tried cookies, i've tried user agents. I'm guessing it records IP addresses on the site, and then checks to see if your still on the site. Because if you just go to the site you will see that you can download without an issue [even on different browsers]. But if you go off the site, and try to use the download URL, it gives you the 403 error. Thats' why i was wondering if curl was able to stay on the site while accessing another part of their site ? I've also tried referrals.

HTTP is stateless, so you should just be able to make a request to some other part of the site.  Perhaps you need to actually make a request to the page that should be the referrer, not just spoof your referrer.

 

How do i do that with curl ? [or fsock ?] I thought i was doing that with curl, but apparently i'm not :|

Heres' what i used to make cookies to make sure its not that , that is causing the issue:

 

	$curl = curl_init(); 
	curl_setopt($curl, CURLOPT_URL,$LOGINURL); 
	curl_setopt($curl, CURLOPT_USERAGENT, $agent);
	curl_setopt($curl, CURLOPT_POST, 1);
	curl_setopt($curl, CURLOPT_POSTFIELDS, $POSTFIELDS); 
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookie.txt");
	curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie.txt");
	curl_setopt($curl, CURLOPT_COOKIE, 1);
	$store = curl_exec ($curl);
	curl_setopt($curl, CURLOPT_URL,$values["video"]);
	curl_setopt($curl, CURLOPT_USERAGENT, $agent);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($curl, CURLOPT_COOKIE, 1);
	curl_setopt($curl, CURLOPT_COOKIESESSION, TRUE);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookie.txt");
	$flv = curl_exec($curl);
	print($flv);exit;		
	fwrite($flash,$flv);
	fclose($flash);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.