Jump to content

form to flat file text script problem.


Recommended Posts

This worked at my old web host. It takes form data from a standard html page, gets called and writes it to a flat text file. Now it just runs and outputs a file with the current date only without any errors. Anyone have any idea what is wrong here?

// Necessary Variables:

$MESSAGE_FILE = "textdata.txt";
// result file

$DEFAULT_EXIT_PAGE = "http://www.yoursite.com/";
// exit page.

// End  Necessary Variables section

function error($error_message) {
echo $error_message."<BR>";

function check_referer () {
if ($HTTP_REFERER != "")
while (list($val, $ref) = each($REFERERS))
if (preg_match("/^http:\/\/$ref/", $HTTP_REFERER))
error("Unauthorized access to: $HTTP_REFERER");


$message = "date : ".date("d/m/Y")."<BR>";

while (list($key, $val) = each($HTTP_POST_VARS)) {
$message .= "$key : ".htmlspecialchars($val)."<BR>";

$message = preg_replace("/\n\r*/", "<BR>", $message);

$file_arry = file($MESSAGE_FILE); //or error("Can not open \$MESSAGE_FILE");
$file = join ("", $file_arry);
$message .= "\n".$file;

$fp = fopen("$MESSAGE_FILE", "w"); // error("Can not write \$MESSAGE_FILE");
flock($fp, 1);
fputs($fp, $message);
flock($fp, 3);

if(! $exit_page)
$exit_page = $DEFAULT_EXIT_PAGE;

Header("Location: ".$exit_page);
// Exit -> $exit_page

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.