Need Some Help In Html+php+cgi+...

Hello!

The whole concept is:

:: I want to have a page that a few people can change its content (plain text) from any PC

I managed to break the problem in these pieces:

:: 1. an html page that includes text from a text file (located in the server)

:: 2. ability to change this text file using a form (like a php form), as FTP access in not always available.

:: 3. authentication, so that not everyone who finds the form URL can change content

Can you suggest a solution or direct me to any tutorials or anything?

Thanks a lot in advance,

Ken

#72913

You can search around http://www.planetsourcecode.com after viewing 5 scripts you need to sign up for an account, but it's free. They also have many languages.

#72917

if what you need is help in code, you need to ask an expert like StevieBM, he knows his stuff... PM him he is extremely helpful

#72924

Okay, here's something I threw together in a few minutes (so it's not perfect ;)) -- I think it's what you want.

You simply choose a file in the code for it to edit. When you type in the right admin name/pass it lets you edit the file and writes to it (make sure the target file is chmodded to 777).

<?php
//authentication
$adminname = "myname";
$adminpass = "foo";

if (!$PHP_AUTH_USER || $PHP_AUTH_PW != $adminpass || $PHP_AUTH_USER != $adminname) {
header('WWW-Authenticate: Basic realm="File Editor"');
header('HTTP/1.0 401 Unauthorized');
echo "<h2>whoops</h2>Access denied y0!";
exit;
} elseif($PHP_AUTH_USER == $adminname && $PHP_AUTH_PW == $adminpass) {
//
//read the file
if(!$file && !$edit_text) {
 //name of the file you're editing
$filename = "testfile.txt";
 //
$handle = fopen ($filename, "r");
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
//
?>
<form action="<?php echo $PHP_SELF; ?>" method="post">
<textarea name="edit_text" cols="50" rows="10"><?php echo $contents; ?></textarea><br/>
<input type="hidden" name="file" value="<?php echo $filename; ?>"/>
<input type="submit" value="Save"/>
</form>
<?php
//write to the file: make sure it's chmodded to 777!
} else {
 if(is_writable($file)) {
 if (!$handle = fopen($file, 'w')) {
    echo "Cannot open file ($filename)";
    exit;
 }
 
 if (!fwrite($handle, stripslashes($edit_text))) {
   echo "Cannot write to file ($filename)";
   exit;
 }
   
 fclose($handle);
 echo "File changes saved. <a href=\"index.php\">Main</a>";
 } else {
 echo "The file $filename is not writable";
 }
}
//
}
?>

Hopefully it looks okay when post :P, if not just PM me or something and I can email you the file.

#72989

It looks perfect at first sight!

I have no experience with php, so I didn't know if it was possible with php only, or anything. Now I'll have to experiment with this code a bit.

Thanks a trillion! (Y)

Ken

#73049