1.

Solve : PHP: Fwrite?

Answer»

Hi,

Normaly, this script shoud add the text to test.txt, but how can you make an text space, and that the file wirte yours text?

$filename = 'test.txt';
$somecontent = "Add to file\n";
?>

O, and i don't think this script works if the file test.txt doesn't exist...
so is there a way to make a file. For instance : Register ; then the file, whit the name that you set as username. In the file is your password. Is that possible?

mikiCurrently your script won't actually do anything other than set two variables.  You're missing the fopen()/fwrite() statements.  Use file_exists() to discover if the file exists.  Recommend you read through the whole FILESYSTEM section of the PHP manual.

Storing passwords in text files in your web root is of COURSE a very bad idea.  Anyone can guess the filename, point their web browser at it and retrieve the password.

You could store the text files somewhere else in the filesystem where only PHP could see them, but if you're serious about creating a secure form of user authentication, then you'd need to do this via a database, with md5 encrypted passwords, etc.so this script shoud work

$filename = 'test.txt';
$somecontent = "add to file\n";

if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'a')) {
         print "cant open ($filename)";
         exit;
   }

      if (!fwrite($handle, $somecontent)) {
       print "can't write ($filename)";
       exit;
   }

   print "Succes: ($somecontent) to file ($filename)";

   fclose($handle);

} else {
   print "can't write $filename ";
}
?>

Quote

Currently your script won't actually do anything other than set two variables.  You're missing the fopen()/fwrite() statements.  Use file_exists() to discover if the file exists.  Recommend you read through the whole Filesystem section of the PHP manual.

Storing passwords in text files in your web root is of course a very bad idea.  Anyone can guess the filename, point their web browser at it and retrieve the password.

You could store the text files somewhere else in the filesystem where only PHP could see them, but if you're serious about creating a secure form of user authentication, then you'd need to do this via a database, with md5 encrypted passwords, etc.


see BOLT : How to make one?



Take it like an web poll service :
1) you need to register, your username and password are stored in the database
2) when you clicked on a link, you get a poll, in for instance 5 hours.
3) the poll is named after the names in 2 lists : in the first list is - 1,2,3,4,... - and in the second - a,b,c,d,... -
4) If the file 1a already exist, the poll is named after 1b, till z, than 2a, ... ect.
5) you can find the poll on the login screen
6) The poll has diferent OPTIONS, but you can't change them. the options are for instance Yes, No and no opinion.
7) if selected No opinion, nothing happens. if selected Yes or No, at 24 o'clock the program wirtes in the poll file, in this example, this is 1a. in the file is Yes: number of votes - No: number of votes
if selected Yes : in the file yes +1


can you make a script please : PS : server is running PHP 4

making such script cost hours and hours of thime. You will need a mysql database too. Can you work with that? I got a good login script from rob, a few topics ago, i'll search the link. But I think you should learn a bit php first. I don't really understand what you want but clearly, you want a huge thing, but you can't write one line of it... that's a bit difficult...

Storing passwords in text files in your web root is of course a very bad idea.  Anyone can guess the filename, point their web browser at it and retrieve the password.

Like rob said, this is a very bad idea. A half year ago I got this idea to, because doing things with a textfile is very easy, but certainly unsafe!I'll GO and learn first Quote
I'll go and learn first


good link: http://www.w3schools.com/


good luck

Quote
Quote
I'll go and learn first


good link: http://www.w3schools.com/


good luck



idd, good site


Discussion

No Comment Found