Writing data to a text file

Monday May 10th 1999 by ServerWatch Staff
Share:

While writing a online signup form I decided to write some of the data to a text file for security reasons. I could've used a database, but the overhead isn't worth it and I only need notepad to open a text file. So, on to the code.

Ian Stallings

While writing a online signup form I decided to write some of the data to a text file for security reasons. I could've used a database, but the overhead isn't worth it and I only need notepad to open a text file. So, on to the code.

First we declare the textfile to be used and if it doesn't exist create it using this:

<%
LogFile = Server.Mappath("log.txt")
Set LogFileObj=Server.CreateObject("Scripting.FileSystemObject")


Set OutStream=LogFileObj.OpenTextFile(LogFile, 8, TRUE)

New_line = Request.Form("UserName") & Chr(13) & Chr(10)

OutStream.WriteLine(New_line)
TextFile.Close
%>

Now we can submit the info we want to collect from a form:

<html>
<head>
</head>
<body>
<form action="writetext.asp" method="post">
Username:<input type="text" size="20" name="UserName">
<input type="submit" name="submit">
</body>
</html>

For this script to work it must have write permission. The text file will be created in the same directory as the script. If you have questions or article ideas feel free to drop me a line.

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved