【发布时间】:2015-09-16 22:14:27
【问题描述】:
这是我的 php 代码,例如我想保护我的表单免受不需要的标签的影响
<a harf='http://anyweb.com'>Look </a> or
<script> something here </script> or
<?php header( "Location:tks.php" ); ?>
我尝试过将任何链接或代码发布到我的表单,但非常困难的是,任何人都可以缩短并轻松保护我的表单免受不需要的链接和代码的影响。 这是我尝试过的代码
<?
$error="";
if(!empty($_POST))
{
if(empty($_POST['name'])){
$error = 'Invalid name. Try again';
}
elseif(empty($_POST['message'])){
$error = 'Invalid message. Try again';
}
elseif(preg_match('/http/',$_POST['name'])){
$error = 'Invalid content message. Try again';
}
elseif(preg_match('/http/',$_POST['message'])){
$error = 'Invalid content message. Try again';
}
elseif(preg_match('/</',$_POST['name'])){
$error = 'Invalid content message. Try again';
}
elseif(preg_match('/</',$_POST['message'])){
$error = 'Invalid content message. Try again';
}
else {
$name = $_POST['name'];
$message = $_POST['message'];
//include('sqlconnect.php');
//$sql = "INSERT INTO msg (name, message, date)VALUES ('$name', '$message', 'now()')";
//mysql_query($sql) or die(mysql_error());
header( "Location:tks.php" );
exit;
}
}
?>
【问题讨论】: