By clicking “Accept All”, you agree to the storing of cookies on your device to enhance site navigation, analyse site usage, and assist in our marketing efforts
These cookies enable our website and App to remember things such as your region or country, language, accessibility options and your preferences and settings.
Analytic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.
Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="script.php">
<p>name:
<label>
<input type="text" name="name" id="name" />
</label>
</p>
<p>email:
<label>
<input type="text" name="email" id="email" />
</label>
</p>
<p>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
</p>
</form>
</body>
</html>
<?php
// the fileyou want your emals n stuff in
$myFile = "saveddata.txt";
$name = $_POST['name']; // the name field in the html <input type="text" name="name" id="name" />
$email = $_POST['email']; // The email field <input type="text" name="email" id="email" />
// magicc happens here
$fh = fopen($myFile, 'a') or die("can't open file"); // Open file in "a" append mode.
$stringData = "Name= $name , Email= $email \n"; // Create the data that we will put in the file. ( \n means "newline" )
fwrite($fh, $stringData); // Write the data
fclose($fh); // close the file.
echo "Thanks, Stuff has been added to our system"; // print to the page that its done
?>
You say this should be secure, well writing to a text file is certainly not secure
If you write to a text file then if they can find where it is a hosted then they can download all of your customers details.
If you want it to be secure then you should use a database or make sure the text file is not in a publicly accessible directory.
It would be quite simple to only give the server FTP user read permissions and not allow the public any permissions with CHMOD.
<?php
die;
/* EMAIL LIST
A safer way would be to locate the text file above the public_html folder (eg on /home/USERNAME/myfile.txt instead of /home/USERNAME/public_html/myfile.txt) - that way only server side scripts should be able to access it.The problem with a text file is if someone finds the path it will simply download. How about using a file with a .php extension and head the file with a die command and open comment.
That would stop it being visible if the path got found.
Code:<?php die; /* EMAIL LIST
A safer way would be to locate the text file above the public_html folder (eg on /home/USERNAME/myfile.txt instead of /home/USERNAME/public_html/myfile.txt) - that way only server side scripts should be able to access it.
Steve
:|Why a text file?
Can you not add them to a database? Then you can do things like having a date and time they are added![]()
Sorry, its a quick 2second writeup..
Something like this will work.
form:
the script that the form calls ( script.php )HTML:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Form</title> </head> <body> <form id="form1" name="form1" method="post" action="script.php"> <p>name: <label> <input type="text" name="name" id="name" /> </label> </p> <p>email: <label> <input type="text" name="email" id="email" /> </label> </p> <p> <label> <input type="submit" name="button" id="button" value="Submit" /> </label> </p> </form> </body> </html>
PHP:<?php // the fileyou want your emals n stuff in $myFile = "saveddata.txt"; $name = $_POST['name']; // the name field in the html <input type="text" name="name" id="name" /> $email = $_POST['email']; // The email field <input type="text" name="email" id="email" /> $mydate = date("F j, Y, g:i a"); // magicc happens here $fh = fopen($myFile, 'a') or die("can't open file"); // Open file in "a" append mode. $stringData = "Name= $name , Email= $email , When= $mydate \n"; // Create the data that we will put in the file. ( \n means "newline" ) fwrite($fh, $stringData); // Write the data fclose($fh); // close the file. echo "Thanks, Stuff has been added to our system"; // print to the page that its done ?>