Page 1 of 1

Txt File PHP Script Needs Mailto: Args...

Posted: Thu Jun 26, 2008 4:45 pm
by MentallyConfused
I have a simple php text file that just captures input and I'd like to beef it up a little so I don't get 5,000 blank msgs when someone keeps hitting the 'submit' button. I have some generic code for limiting text and forcing the user to enter info before sending, but I think thats more for a mailto: php form.

Code: Select all

 
<HTML>
<HEAD>
<TITLE> Register </TITLE>
</HEAD>
<BODY>
 
<?php
 
$out = fopen("register.txt", "a");
 
if (!$out) {
    print("server is down, please try later");
    exit;
}
 
fputs($out,"$_POST[name]\n");
 
print("Thank You!");
 
 
fclose($out);
 
?>
 
</BODY>
</HTML>
 
Generic code for 'character force'(which I stole from a tutorial) are:

Code: Select all

 
if(strlen($name) == 0)
{
echo "It would appear that you have not put your Name in the Name Field. Please use the Back Button to return to the form and put your Name in that field. Thank you!";
exit;
}
 
They're all "IF" strings for character limits, and such to help protect against injection, but my initial args were for:

Code: Select all

 
$name = $HTTP_POST_VARS['name'];
 
I know it's kind of confusing, but the first code I posted works great for simple name capture and I can always expand it for other fields(I just wanted to get it working). But it's only a txt file capture, which I don't care about since i'm always signed on working on the website anyways. I think I'm confusing the mailto: args because I can't seem to incorporate 'if' args in my statements.

Anybody have a workthrough for this? or am I jsut gonna have to dump my txt file all the time for blank submits?

MC

Re: Txt File PHP Script Needs Mailto: Args...

Posted: Sat Jun 28, 2008 12:38 am
by MentallyConfused
<HTML>
<HEAD>
<TITLE> Register </TITLE>
</HEAD>
<BODY>

<?php

Code: Select all

 
$name = $_POST['name']; // HTTP_POST_VARS is depricated
 
if(strlen($name) == 0)
{
     echo "It would appear that you have not put your Name in the Name Field. Please use the Back Button to return to the form and put your Name in that field. Thank you!";
exit;
}
 
$out = fopen("register.txt", "a");

if (!$out) {
print("server is down, please try later");
exit;
}

fputs($out,"$_POST[name]\n");

print("Thank You!");


fclose($out);

?>

</BODY>
</HTML>

It was suggested that I put this string in like this and it just blanks my page out. no data is even recorded either... :?

MC

Re: Txt File PHP Script Needs Mailto: Args...

Posted: Sat Jun 28, 2008 3:39 am
by Mordred

Code: Select all

fputs($out,"$_POST[name]\n");
should be

Code: Select all

fputs($out,"$name\n");

Re: Txt File PHP Script Needs Mailto: Args...

Posted: Mon Jun 30, 2008 5:37 pm
by MentallyConfused
Thx Mordred,

It works! The only thing is now it looks crappy. It's a long cheesy notepad looking statement that says: you didn't fill in... hit back button... all on a giant white blank page.

I thought it would be an instantaneous greyed-out pop-up response that was on the same user page you were typing in...

Oh, well, I'm sure I have the getto version. Anyways, THX Mordred for the debugging!

I'm looking to post more if statements like:

Code: Select all

 
if (strlen($email) >= 45 )
{
echo "You have placed too many characters in the Email field - please shorten the entry. Thank You!";
exit;
}
 
and

Code: Select all

 
if (substr_count($comments , '@') > "2")
{
echo "For security reasons this text (comments) area limits the number of @ symbols that can appear within it. It would appear that you have exceeded that number. Please use the Back Button to return to the form and correct this. Thank you for your patience!"
exit;
}
 
But if I hit a snag, i'll post here in a few...

MC