I downloaded a simple contact script
and changed it to not send email
but store submitted user data in a textfile.
Of course you should modify script to fit your needs
maybe you need no subject and message
and change the link to go after data is saved
Files organisation:
ROOT folder:
contact.php - here is the submit form
save.php - this file checks submitted fields and saves to './data/persondata.txt'
---- data (subfolder with chmod 777 = write permission for everybody)
-------- .htaccess ( Deny from all ) so people can not read data
-------- persondata.txt (the file where userdata is saved, appended)
contact.php
<form method="post" action="save.php">
Name:<br /><input name="name" type="text" size="30" maxlength="40" /><br /><br />
Email:<br /><input name="email" type="text" size="30" maxlength="40" /><br /><br />
Subject:<br /><input name="subject" type="text" size="30" maxlength="40" /><br /><br />
Message:<br /><textarea name="msg" cols="50" rows="6"></textarea><br /><br />
<input type="reset" value="Reset" /> <input type="submit" value="Send" />
</form>
save.php
<?php
// error_reporting(E_ALL); // uncomment this line while debugging only
$file = "./data/persondata.txt";
$sep = " - ";
$name = ltrim(rtrim(strip_tags(stripslashes($_POST['name']))));
$email = ltrim(rtrim(strip_tags(stripslashes($_POST['email']))));
$subject = ltrim(rtrim(strip_tags(stripslashes($_POST['subject']))));
$msg = ltrim(rtrim(strip_tags($_POST['msg'])));
$ip = getenv("REMOTE_ADDR");
// VALIDATION
if(empty($name) || empty($email) || empty($subject) || empty($msg)) {
echo "<h3>Your data was not valid</h3><p>Please fill all the required fields</p>";
}
elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
echo "<h3>Your data was not valid</h3><p>The email address is not correct</p>";
}
else {
$userdata = $ip.$sep.$name.$sep.$email.$sep.$subject.$sep.$msg."\n";
$fp = fopen( $file, "ab" );
if ( !fwrite( $fp, $userdata ))
die( 'file write error' );
else
echo "<h3>Your data has been saved</h3><p>Thank you!</p><p><a href='index.html'>Back to index.html</a></p>";
}
exit;
?>
.htaccess
Deny from all
persondata.txt
will store data like this:
213.100.118.115 - halojoy - dfg@hgj.com - hej - pa dej
213.100.118.115 - halojoy - dfg@hgj.com - hej - pa dej
213.100.118.115 - halojoy - dfg@hgj.com - hej - pa dej
IPadress - name - email - subject - message
🆒