Jump to content

content from URL - login problem


wasssu

Recommended Posts

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

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.

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.