Page 1 of 1

Secure 1 field php form - help

Posted: Thu Apr 05, 2012 12:28 pm
by Davidjohny
Hello
I have a website with an online email newsletter subscription form in PHP.

Current status:

Step1/- A visitor fills in his email address.
Step 2/- Next, I get visitor email address inside my INBOX.

Current PHP form consist of two pages

================================================
[[[ Page with PHP Form Code | Page NO.1 Formpage.php ]]]

<html><body>
<form name="myform" method="post" action="SEND.php"><br> <br />
<input name="email" type="text" id="email" />
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
</body></html>
================================================
[[[ Confirmation Page Code | Page NO.2 SEND.php ]]]

<?php
$email = $_REQUEST['email'] ;
mail( "myemail@mydomain.com", "Newsletter Request", "From: $email" );
?>
================================================
I have heard about php code injection, malicious script and spam.
How can I secure this simple php two pages form?

Best wishes,
Dave
============

Re: Secure 1 field php form - help

Posted: Thu Apr 05, 2012 6:09 pm
by social_experiment
Davidjohny wrote:I have heard about php code injection, malicious script and spam.
How can I secure this simple php two pages form?
It's good practise to check the input you receive; check that the data you receive is an email address by using regular expressions. Regarding spam you could implement captcha or a human-test system where a user has to answer a question, type in some word, etc. Check that the form was submitted from your site: set a session variable (or value in a hidden field) and do a check on this value before processing the form

Code: Select all

<?php $email = $_REQUEST['email'] ; ?>
If you have the method of your form as 'post' use $_POST instead of $_REQUEST.

Re: Secure 1 field php form - help

Posted: Thu Apr 05, 2012 6:14 pm
by Celauran
social_experiment wrote:Regarding spam you could implement captcha or a human-test system where a user has to answer a question, type in some word, etc.
And/or use a honeypot.

Re: Secure 1 field php form - help

Posted: Fri Apr 06, 2012 12:30 am
by social_experiment
Celauran wrote:And/or use a honeypot.
Interesting; how would this be setup, if i only have access to one web server? Or is this something that will only work on a network?

Re: Secure 1 field php form - help

Posted: Fri Apr 06, 2012 6:31 am
by Celauran
A simple honeypot can consist of a form field hidden by CSS. Humans won't see it, so they won't fill it in. Bots will see it, however, and tend to fill in everything. If that field contains data, discard the post.

Re: Secure 1 field php form - help

Posted: Fri Apr 06, 2012 5:28 pm
by social_experiment
Ah ok; thanks for the idea :)

Re: Secure 1 field php form - help

Posted: Thu Apr 26, 2012 7:37 am
by Gopesh
Thanks Celauran for the idea of honeypot..:D

Re: Secure 1 field php form - help

Posted: Thu Apr 26, 2012 10:07 am
by x_mutatis_mutandis_x
Celauran wrote:A simple honeypot can consist of a form field hidden by CSS. Humans won't see it, so they won't fill it in. Bots will see it, however, and tend to fill in everything. If that field contains data, discard the post.
Thats very clever and ingenious