在這裏,我試圖發送一個聯繫表格值到電子郵件ID。我已經發布了contact.php頁面代碼。我在同一頁面上完成了服務器端驗證。驗證成功完成後,它應該重定向到email.php頁面。我應該怎麼做?驗證成功完成重定向到email.php頁面
Contact.php
<?php
$errname = "";
$errmotorcycle = "";
//some codes
if($_POST["contacts"] == "all")
{
// name validation
if(empty($_POST["name"]))
{
$errname = '<span class="error">Should not be empty</span>';
}
else if(preg_match("/^[a-zA-Z ]+$/", $_POST["name"]) === 0)
{
$errname = '<span class="error">Name must be from letters and spaces only</span>';
}
else
{
$errname = '';
}
// motorcycle validation
if($_POST["typeofmotor"] == "empty")
{
$errmotorcycle = '<span class="error">You must select one option</span>';
}
//some codes
}
?>
<html>
<head><title></title></head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input type="hidden" name="contacts" value="all" />
<table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="281" height="40" class="rightalign">Name : </td>
<td width="268"><input type="text" name="name" class="normal" value="<?php $_POST['name']; ?>" /></td>
<td width="431" valign="middle"><?php if(isset($errname)) echo $errname; ?></td>
</tr>
//some codes
</table>
</form>
</body>
</html>
如果你在一個PHP請求驗證,然後重定向到電子郵件的PHP腳本,如果全成,從什麼直接調用你的電子郵件的PHP腳本繞過您的任何驗證的停止攻擊?不要這樣做!使用包含和處理相同的請求。 – ToBe
@ToBe:那麼我應該在email.php頁面上進行驗證嗎? – Karuppiah
只要你在發送的同一頁面上完成(包括一個PHP是完美的),你就很好。 – ToBe