Go Back   WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk
Register Blogs FAQ Social Groups CalendarHelp Desk

Reply
 
LinkBack Thread Tools
Old 07-12-2009, 02:53 AM   #1
Active Warrior
 
PsiCat's Avatar
 
Join Date: Jun 2009
Posts: 55
Thanks: 23
Thanked 3 Times in 3 Posts
Default Newbie PHP Form processing + Security questions.

Hi Everyone,

I am trying to create the code that works behind the submit button on my squeeze page.

I need it to:
1) Send me an email with all the user enter data from the form
2) Redirect the user to my "Thank You" page
3) Populate my newly created MySql database with the appropriate info.

I'm VERY new to php, but I've actually created a php file that seems to be doing all this, but it has my email, my DB Username and password in it, and that feels dangerous.

I don't know anything about how security works, so I just tossed the file in the same directory that I have my all my other html pages.

First off, can someone please take a quick look and tell me if there are any pitfalls with this code that I should be aware of (like it won't work in some browsers, or something):

<?php
// Define data fields:
$email = $_POST['email'];
$name = $_POST['name'];
$to = "myEmail@mydomain.com";
...
//
//Email and then redirect to thanks page
mail($to, $subject, $body, $from);
header('Location:http://mydomain.com/Thanks.html');
//
//Store data in a database:
mysql_connect("localhost", "userid", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
mysql_query("INSERT INTO `tablename` VALUES ('$email', '$name', '$PictureVote', '$ProdReviewer', '$NotifywhenReady')");
?>

Second, can anyone explain to me in agonizing detail what I should be doing so that bad people can't somehow get their paws on this code to spam my email and/or hack my db?

(I've made this particular userid/password with limited privelege of insert only which should help, but I still don't want anyone to see anything.)

I imagine that as it stands right now, someone clever could simply view the source data right now to find the name of the file "processform.php" and then do nasty things to me.

I'm using hostgator, by the way, in case that means anything to anyone as far as including specifics in your answers.

Thanks in advance for helping out!

- PsiCat!

Check out Miracle Mastery and explore the Psychic Development of *Physical* abilities you can actually see, like telekinesis and radical Healing!
PsiCat is offline   Reply With Quote
Old 07-12-2009, 03:54 AM   #2
Active Warrior
 
Join Date: Apr 2009
Posts: 36
Thanks: 0
Thanked 2 Times in 2 Posts
Default Re: Newbie PHP Form processing + Security questions.

Just some Quick pointers:

You may want to perform strip_tags, stripslashes on the posted data to stop the user from modifying your MySQL query.

You may also want to check their referring page to ensure their coming from the correct page on you website and not a direct link

You might want to clean and validate your data - not for security but to ensure that the correct information has been entered.

You could also add a simple captcha? Therefore stopping any bots from submitting the form


Hope this helps,
Adi
Adi E is offline   Reply With Quote
Old 07-12-2009, 05:16 AM   #3
HyperActive Warrior
 
Join Date: Apr 2006
Location: , , United Kingdom.
Posts: 150
Thanks: 13
Thanked 5 Times in 5 Posts
Default Re: Newbie PHP Form processing + Security questions.

You could hide your email by breaking it up, and replacing the "@" with chr(64):

E.g.
$to = "myE" . "ma" . "il" . chr(64) . "myd" . "om" . "ain" . ".c " . "om";

hiphil is offline   Reply With Quote
Old 07-12-2009, 07:28 AM   #4
A rat after money...
War Room Member
 
HomeBizNizz's Avatar
 
Join Date: Jul 2009
Location: Inside a cheese...
Posts: 598
Thanks: 363
Thanked 54 Times in 47 Posts
Default Re: Newbie PHP Form processing + Security questions.

PHP-code will always be processed before it is sent to the browser.
If the file has the right ending, like .php
I don't think you will see none of that, just the output in text/HTML.

HomeBizNizz is offline   Reply With Quote
Old 07-12-2009, 08:55 AM   #5
Active Warrior
 
Join Date: Apr 2009
Posts: 36
Thanks: 0
Thanked 2 Times in 2 Posts
Default Re: Newbie PHP Form processing + Security questions.

HomeBizzNizz is right, theres no way for someone to find your database details when they access the page via a web browser, but if they somehow gain FTP access to your site then this would allow them to download the file and see your details,

Adi
Adi E is offline   Reply With Quote
Old 07-12-2009, 10:22 AM   #6
HyperActive Warrior
 
Join Date: May 2008
Location: USA
Posts: 249
Blog Entries: 22
Thanks: 9
Thanked 29 Times in 27 Posts
Default Re: Newbie PHP Form processing + Security questions.

Couple of considerations . . .

- sanitize your input fields to make sure only data is being submitted, instead of database commands or scripting variables, there are plenty of free Javascript and PHP codes that you can simply copy and paste on your form page, the fields are checked before form submission

- make your job easier by using cforms II, search google for Delicious Days to download the latest cforms version, there are a lot of built-in features, and it's all free

- be aware of SQL injection techniques, scan your database for vulnerabilities and patch it correctly before you rely on it for a business production environment

- either check your web server logs manually each day, or setup an automated pattern matching search in your logs to immediately alert you when a serious error or problem shows up, you want to respond as quickly as possible to prevent damage and limit data corruption

- make regular backups of your data, and create a schedule to regularly change your passwords

- use SSL certificates (HTTPS) on form pages to encrypt the data that is being submitted on your web server, otherwise everything can be intercepted and read as cleartext

- use SSH (jailed root, secure shell) to access your web hosting account instead of FTP or telnet, otherwise everything you are doing can be intercepted and read as cleartext

There's more but this is a good start. The main idea is that you are aware and alert.

awesometbn is offline   Reply With Quote
Old 07-12-2009, 10:40 PM   #7
Active Warrior
 
PsiCat's Avatar
 
Join Date: Jun 2009
Posts: 55
Thanks: 23
Thanked 3 Times in 3 Posts
Default Re: Newbie PHP Form processing + Security questions.

Wow!

Thanks for the great replys everyone.

Being very new to this, I've had to do some reading to figure out what you were all talking about, but it is very much appreciated.

I now know what a captcha and strip_tags is, I've got validation on all fields except email, and I'm looking into that, I've butchered my email address in spite of the fact that it sounds like people will not be able to look inside my php code, and I am horrified to learn that "sql injection" exists and am now studying up on what that means to me, and how to avoid it.

What a great bunch of info! Thanks to everyone who wized me up. Clearly I came to the right place!

- PsiCat

Check out Miracle Mastery and explore the Psychic Development of *Physical* abilities you can actually see, like telekinesis and radical Healing!
PsiCat is offline   Reply With Quote
Reply

  WarriorForum - Internet Marketing Forums > Warrior Support Forums > Programming Talk

Tags
form, newbie, php, processing, questions, security

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -6. The time now is 11:16 PM.