chmod 777 and fwrite

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

chmod 777 and fwrite

Post 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.
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post by sheila »

You're cracked and it won't work. :)
http is a read-only protocol
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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.
Post Reply