Page 1 of 1

chmod 777 and fwrite

Posted: Sun Dec 04, 2005 3:07 pm
by neophyte
This has probably been asked before but here goes. I have chmod'd a file to 0777 on one site. I'm trying to write to that file from another site using an "http" address for the file location. What would prevent me from writing to the file? I did a is_writable() test on the file and didn't succeed. Any comment on today's experiment would be appreciated... Thanks.

Code: Select all

<?php
$file = "http://www.ritterfamily.org/rf/this.html";
   if ($fh = @fopen($file, 'w')) {
       while(!feof($fh)){
        echo fgets($fh);
        }
       if(fwrite($fh, "You've been pwnd")== 0){
        fclose($fh);
       } else {
        echo "no write";
       }
  } else {
    echo "not open";
  }
?>
Yes that's the address. There must be something I'm not understanding. Feel free to tell me I'm cracked and it won't work.

Posted: Sun Dec 04, 2005 3:51 pm
by sheila
You're cracked and it won't work. :)
http is a read-only protocol

Posted: Sun Dec 04, 2005 6:28 pm
by josh
FTP, or



have a script on server A (the one with the file to write to),


your script on server B sends an http request to server A using POST (with curl)

Script on server A reads the file from the post data and writes it to the file.


You can write a file wrapper on server B to allow you to just fwrite() to the file on server A (using previously mentioned technique)

Posted: Sun Dec 04, 2005 7:52 pm
by neophyte
Thanks jshpro2. I was wondering how I might do it. But in short, there really is no way to do unless the script that is executing fwrite() is on the same server. Your cURL thing is a great idea.

That clears things up.

Posted: Sun Dec 04, 2005 8:42 pm
by josh
neophyte wrote: there really is no way to do unless the script that is executing fwrite() is on the same server.
Over the HTTP protocol, no.

No problem, and another way to do it, if you didn't want your [sensitive] data over port 80, would be to write your own protocol using tcp/ip (php's socket functions), this is the same idea as the fwrite() script though.