wasssu Posted January 22, 2010 Share Posted January 22, 2010 Hi, I'm trying to get the content of a file from a specific URL (EX: http://www.test.com/abc.torrent). But i have to be logged in to have access to that file. Is any way to pass to the website the user and the password? Thank you. <?php error_reporting(-1); $handle = fopen("http://www.test.com/abc.torrent", "r"); $contents = ''; while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle); echo $contents; ?> Link to comment https://forums.phpfreaks.com/topic/189433-content-from-url-login-problem/ Share on other sites More sharing options...
simonrs Posted January 22, 2010 Share Posted January 22, 2010 Yes there is, but it depends greatly on how the site processes logins. You may need to do two seperate requests, one to login, and one to fetch the file. Examples of how the login might be processed could be through a .htaccess or by posting get or post variables along with the request. In the past I've used something like: $ctx = stream_context_create($params); try { $fp = @fopen($url, 'rb', false, $ctx); } catch(Exception $e) { return false; } $response = @stream_get_contents($fp); return $response; Where the $params variable has get, post or a header with a username and password for .htaccess in. Difficult to help more without knowing exactly how the site processes logins. Link to comment https://forums.phpfreaks.com/topic/189433-content-from-url-login-problem/#findComment-999968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.