Click to See Complete Forum and Search --> : U have time to loose ? PHP newbie needs help here ! :-)


[Mystik_Cool]
12-03-2002, 10:59 AM
I'd like to write a simple php script for my website. The best would be a script which prints two fields : one simple "Subject" field, and a bigger "Message" field. Then a submit button.
When the user has entered his message, when he presses "submit", the prog should simply add the message as a text file to the FTP of my website, with the name "date_of_submitting-title.txt" (the title would be what the user entered in the "Subject" field).

As I don't know anything in PHP and as I don't have ANY time to spend learning it now, I was wondering if someone who has nothing more interesting to do could post the code here (I don't think this would be a really long code)... That would be soooooo great !

Thanx a lot for any code-suggestion !

Rüpel
12-03-2002, 04:58 PM
form.html

<html>
<head>
<title>The Form</title>
</head>
<body>
<form action="save.php" method="post">
Subject:<br>
<input type="text" name="subject"><br>
Message:<br>
<textarea name="message"></textarea><br>
<input type="submit" value="Submit">
</form>
</body>
</html>


save.php

<?php

if (!isset($HTTP_POST_VARS["subject"]))
{
echo "Subject missing!";
exit;
}

if (!isset($HTTP_POST_VARS["message"]))
{
echo "Message missing!";
exit;
}

$subject=str_replace(" ","_",$HTTP_POST_VARS["subject"]);
$filename = date("d-m-Y_H-i-s")."-".$subject.".txt";
$f = fopen($filename,"w");
$w=fwrite($f,$HTTP_POST_VARS["message"]);
echo $w." bytes written into ".$filename;
fclose($f);

?>


make sure the script has the right to write into the current directory on the server. (chmod 775 .)

this should be only the first version! i'm pretty sure this is not "production-quality".

[Mystik_Cool]
12-04-2002, 03:27 AM
Great, many many thanx to you ! Many months I'd like to learn PHP but I never have any free time...

About security, isn't it risky to put a php script with the write access on my website ? (But anyway that's a website only for me and some friends, there will be a password to enter...)

Rüpel
12-04-2002, 05:31 AM
Originally posted by [Mystik_Cool]
About security, isn't it risky to put a php script with the write access on my website ? (But anyway that's a website only for me and some friends, there will be a password to enter...)

definitely there's some security risk. i can't spot it (i'm not very experienced with these issues) but locking access to that area via password seems to be a good idea. use apaches .htaccess-method. this way the complete directory is secure (if you just limit the access to form.html, someone could call save.php directly).

[Mystik_Cool]
12-04-2002, 06:17 AM
I'll lock the whole website, so this should be ok.

Thanx for all the help