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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :|

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.