jmqbe Posted November 22, 2011 Share Posted November 22, 2011 Hi, I am looking to fetch the contents of https://bb.kdg.be/webapps/blackboard/content/listContent.jsp?course_id=_98522_1&content_id=_1288143_1 in PHP However, the page works with cookies, javascript redirect, and https. Therefor I cannot manage to make a local copy of the actual contents. I have tried with curl, file_get_contents, file, fopen, and numerous user-written functions online, none of which worked. Please make sure you TEST your answer before posting it, because it is probably not as obvious as it seems! Thanks! Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/ Share on other sites More sharing options...
teynon Posted November 22, 2011 Share Posted November 22, 2011 This code worked fine for me: <?php $contents = file_get_contents("https://bb.kdg.be/webapps/blackboard/content/listContent.jsp?course_id=_98522_1&content_id=_1288143_1"); echo $contents; ?> I did have to enable the extension php_openssl first though. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290425 Share on other sites More sharing options...
jmqbe Posted November 22, 2011 Author Share Posted November 22, 2011 Then somehow you also managed to get your PHP to save cookies, any idea how? On 'my' server, the file_get_contents fetches a page that just contains a javascript redirect. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290437 Share on other sites More sharing options...
teynon Posted November 22, 2011 Share Posted November 22, 2011 Heh, yep. Just ran a quick test so it was just redirecting to the contents. Might I point out, that the reason this site is like this looks like it is purposely trying to prevent this type of thing. You could do it with another language. I don't know if you can do it with PHP. But it might be quite involved. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290441 Share on other sites More sharing options...
jmqbe Posted November 22, 2011 Author Share Posted November 22, 2011 OK, thanks for trying. I am aware that they do try to block this, but no harm is intended in my case Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290446 Share on other sites More sharing options...
xyph Posted November 22, 2011 Share Posted November 22, 2011 If they're trying to prevent this then they probably don't allow it. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290450 Share on other sites More sharing options...
Philip Posted November 22, 2011 Share Posted November 22, 2011 I am aware that they do try to block this, but no harm is intended in my case At least in your eyes it is no harm, but in the website owner's eyes, it is harm. The only reason you'd be doing this is to scrape their page, no? Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290452 Share on other sites More sharing options...
ManiacDan Posted November 22, 2011 Share Posted November 22, 2011 Please don't report posts simply because you don't like what they say. If someone purposely obfuscates their website so you cannot make a copy of it, then they do so for a reason. Downloading a copy of a website is illegal in the United States and in many other countries (I am not a lawyer). There exists a PHP class that emulates a browser {url removed}, complete with cookie storage and retrieval, but it does not parse javascript. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290461 Share on other sites More sharing options...
Pikachu2000 Posted November 22, 2011 Share Posted November 22, 2011 Since you already know that the site blocks this, there's no reason to pursue this further. We don't provide help to people trying to circumvent systems that were put in place to prevent access to content in ways it wasn't intended to be accessed. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290462 Share on other sites More sharing options...
ManiacDan Posted November 22, 2011 Share Posted November 22, 2011 Now that there's two mods saying the same thing, I'm closing this thread. Link to comment https://forums.phpfreaks.com/topic/251619-php-advanced-fetch-of-external-file/#findComment-1290483 Share on other sites More sharing options...
Recommended Posts