lordphate Posted January 15, 2009 Share Posted January 15, 2009 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 https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/ Share on other sites More sharing options...
corbin Posted January 15, 2009 Share Posted January 15, 2009 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 https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/#findComment-737497 Share on other sites More sharing options...
lordphate Posted January 15, 2009 Author Share Posted January 15, 2009 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 https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/#findComment-737499 Share on other sites More sharing options...
corbin Posted January 15, 2009 Share Posted January 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/#findComment-737505 Share on other sites More sharing options...
lordphate Posted January 15, 2009 Author Share Posted January 15, 2009 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 https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/#findComment-737510 Share on other sites More sharing options...
corbin Posted January 15, 2009 Share Posted January 15, 2009 Oh it does look like you're doing that.... Hrmmmm..... Link to comment https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/#findComment-737513 Share on other sites More sharing options...
lordphate Posted January 15, 2009 Author Share Posted January 15, 2009 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 https://forums.phpfreaks.com/topic/140899-stay-on-a-site-and-download-a-file-using-curl-and-php/#findComment-737521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.