Forum Thread: Trying to Create a .Php File That Stores User Inputs

I am tyring to have the password and username of a user that that types in appear in a file

1 Response

PHP is a server-side scripting language that preprocesses and manipulates HTML among other things. The PHP file itself would likely be the file for the webpage that stores the HTML, PHP, JS, CSS, etc. code.

What you would want to do is create forms in HTML, capture the form data with PHP global variables (i.e. $_POST), then still using PHP tell it to store that information in a separate file (a file that is not .php). You could go with CSV, txt, and many others. You could also have it uploaded straight into a database like MySQL. Your code for writing it to a .txt file would probably look something like this:

<form action="<?=$_SERVER['PHP_SELF'];>" method="post">
<input type="text" name="username" placeholder="username">
<br/>
<input type="password" name="password" placeholder="password">
<br/>
<input type="submit" name="submit">
</form>
<?php
if (array_key_exists("submit", $_POST)) {
$fp = "./usernames_and_passwords_list.txt";
$yourfile = fopen($fp, "a");
fwrite($yourfile, "Username: " . $POST["username"] . "\n" . "Password: " . $_POST["password"] . "\n");
fclose($yourfile);
}
?>

It's not perfect, but essentially that's what you need to capture usernames, passwords and more from PHP forms and store them in files.

If you are wanting to store user inputs from a source other than a webpage, then I would recommend learning a programming language like Python. The idea would still be the same though, get inputs which are stored in variables and then write those variables into files, using Python's syntax.

Javascript is also a possibility, but the implications are that this script is running on a browser or mobile application instead of on your server (unless you use node.js).

Share Your Thoughts

  • Hot
  • Active