tokyo_robot
12-23-2006, 08:07 AM
Let me start out by saying that I'm not using SQL or any databases...
With that said, below is a script that uses superglobal arrays to pass data to a form using a URL like: http://www-site-com/index.php?price=100.00&title=laptop
What would you do to make this script more secure?
<?php
function getIt($value){
if($_GET[$value]) {
switch ($value) {
case 'price':
$pattern = '/^[$0-9.]{1,20}$/';
break;
case 'title':
$pattern = '/^[0-9a-zA-Z]{1,100}$/';
break;
}
if (preg_match($pattern,$_GET[$value])) {
return $_GET[$value];
}
}
return false;
}
?>
<input type="text" name="price" value="<?php echo getIt("price")?>">
<input type="text" name="title" value="<?php echo getIt("title")?>">
Can you spot any security holes?
Thanks!
With that said, below is a script that uses superglobal arrays to pass data to a form using a URL like: http://www-site-com/index.php?price=100.00&title=laptop
What would you do to make this script more secure?
<?php
function getIt($value){
if($_GET[$value]) {
switch ($value) {
case 'price':
$pattern = '/^[$0-9.]{1,20}$/';
break;
case 'title':
$pattern = '/^[0-9a-zA-Z]{1,100}$/';
break;
}
if (preg_match($pattern,$_GET[$value])) {
return $_GET[$value];
}
}
return false;
}
?>
<input type="text" name="price" value="<?php echo getIt("price")?>">
<input type="text" name="title" value="<?php echo getIt("title")?>">
Can you spot any security holes?
Thanks!