Jump to content

How to write a file opened from fopen("URL")


galayman

Recommended Posts

Hi guys

I have this code

<?
// the site we want to read
$host = "www.some-site.com"; 
// the file we want to read
$file = "some-file.htm";

// construct a header for our request
$hdrs = array( 'http' => array(
    'method' => "POST",
    'header'=> "accept-language: en\r\n" . 
        "Host: $host\r\n" .
        "Referer: http://$host\r\n"
    )
);

$context = stream_context_create($hdrs);
$fp = fopen("http://" . $host . "/" . $file, 'r', false, $context);

// $contents = Here I don't know how to read inside $fp 
------- Missing code -------
$file = fopen("/home/user/my_file", "w+");
fwrite ($file, $contents);

fclose($file);
fclose($fp);
?>

 

This code is to read file from somesite, the page is protected using referrer, everyday i open the site using browser, but i need to read it quickly, thats why i use that script.

 

I need to write the content to my_file located at /home/user/

 

The question is, how to read $fp in string ? In the end it will writed to my_file

 

Please help, I already using fgets, fread, file_get_contents. I'm new to php, that's why i cannot solve this problem.

 

Thank You.

Link to comment
Share on other sites

Whats wrong???

It's useless anyway to protect it, because, if we can read it, we can get the contents, i'm not trying to attack it, i just need the contents. I read a lot of web everyday, i want to make my own single page, and inside it will display all the info that i've saved before using this method.

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.