I am building a website that has user registration. I have almost finished the form with javascript checking user input...etc.
However, im not sure how i can properly check user input on the server side using php. At present i have a class called security, eventually i will have all data passed through this class.
The main registration page that takes the data is below:
<?php
require("classes/database.php");
$database_fun = new database();
$check_Fields = new security();
include("include/header.php");
if(!isset($_POST['submit'])){
echo "hacker attempt";
return;
}else{
$key = md5(rand());
// run $_POST through security class
$regPosts = $check_Fields->postvars($_POST);
if($database_fun->query("insert into user values(
'','".$regPosts['artType']."','".$regPosts['username']."','".$regPosts['pass1']."','".$regPosts['email']."','".$regPosts['country']."',
'".$regPosts['city']."','".date('H:i, jS F')."','".date('H:i, jS F')."','".$regPosts['website']."','".$regPosts['biography']."',
'".$key."')")){
// eventually an email will be created and sent to the user
echo "Your details have been emailed to you please activate your account using the link in your email<br />
www.theglobalarts.com/profile.php?activate=$key";
}else{
die("The system was unable to create a new user");
exit;
}
}
include("include/footer.php"); ?>
?>
The postvars function in the security class just "addslashes()" to the $_POST values like the below:
function postvars($postFields){
foreach($postFields as $name=>$value){
$posts[$name] = addslashes($value);
$counter ++;
}
return $posts;
}
The above function is ready to check all the values from the $_POST and throw an error if something is not correct and validate all the users input - im just not sure what else to check for and how? Any pointers really appreciated.