坦率地說,我不是一個編碼怪胎。基本上,這個PHP腳本驗證名稱&「通訊訂閱」表單的電子郵件字段。那麼,所有瀏覽器上的一切似乎都可以正常工作。 2天后,此腳本停止在IE9的工作& Firefox 14-16。它在Chrome上運行良好。請問你們讓我知道,是什麼原因導致了這個錯誤?重定向請求永遠不會完成 - Ant腳本與PHP腳本錯誤?
php腳本名爲signup.php
在代碼中的「回聲腳本警報」似乎並沒有在FF & IE9工作。它在Chrome上運行得非常好。這正是我的問題。
Firefox上的錯誤 - Firefox檢測到服務器以永遠不會完成的方式重定向該地址的請求。 此問題有時可能由禁用或拒絕接受Cookie引起。
Firefox上的操作點 - 所有必要的操作都是爲了應對此錯誤。什麼都沒有解決。
IE9上的錯誤 - 它只是不響應,並停留在同一頁面上。
<?php
ob_start();
session_start();
/*Name Validation.*/
function checkName($name)
{
$nAccept = array("&", "’", " ", "-");
if (!ctype_alpha(str_replace ($nAccept, "", $name)))
{
return TRUE;
}
}
/*Email Validation.*/
function checkEmail($email)
{
if(mb_eregi("^[a-zA-Z0-9_][email protected][a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
{
return FALSE;
}
if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/i", $email))
{
return false;
}
list($Username, $Domain) = explode("@",$email);
if(getmxrr($Domain, $MXHost))
{
return TRUE;
}
else
{
if(fsockopen($Domain, 25, $errno, $errstr, 30))
{
return TRUE;
}
else
{
return FALSE;
}
}
}
function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}
if(checkName($_REQUEST['name']) == TRUE) {
echo "<script>alert('Please enter a Valid Name.');history.back();</script>";
}
elseif (!isset($_POST['email'])) {
echo "<script>alert('Please ensure you have completed all fields before submitting the form. No fields to be left blank.');history.back();</script>";
}
elseif (empty($_POST['name']) || empty($_POST['email'])) {
echo "<script>alert('Please ensure you have completed all fields before submitting the form. No fields to be left blank.Type in only one valid email address.');history.back();</script>";
}
elseif (isInjected($_POST['email'])) {
echo "<script>alert('Please ensure you have completed all fields before submitting the form. No fields to be left blank.Type in only one valid email address.');history.back();</script>";
}
elseif(checkEmail($_REQUEST['email']) == FALSE) {
echo "<script>alert('Entered E-Mail is Invalid or The E-Mail does not belong to a valid domain.');history.back();</script>";
}
else{
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="test"; // Database name
$tbl_name="connect_members_temp"; //table name
mysql_connect("$host", "$username", "$password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");
$confirm_code=md5(uniqid(rand()));
$name=$_POST['name'];
$email=$_POST['email'];
$sql="INSERT INTO $tbl_name(confirm_code, name, email)VALUES('$confirm_code', '$_POST[name]', '$_POST[email]')";
$result=mysql_query($sql);
}
mysql_close();
if($result)
{
// send e-mail to
$to= '[email protected]';
$thankyou_page = "before_subscription.html";
$email_page = "email_connectivity.html";
$data_page = "email_not_found.html";
$subject="Confirm Your Subscription with XXXXX";
$header="from: XXXXX <[email protected]>";
$message="Your Confirmation link \r\n";
$message.="Click on this link to confirm your subscription \r\n";
$message.="http://localhost/XXXXX/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
}
else
{
header("Location: $data_page");
}
if($sentmail)
{
header("Location: $thankyou_page");
}
else{
header("Location: $email_page");
}
?>
下面是HTML表單
<form action="signup.php" method="post">
<fieldset>
<legend>Digital Newsletter</legend>
<div class="fl_left">
<input type="text" name="name" value="Enter name here…" onfocus="this.value=(this.value=='Enter name here…')? '' : this.value ;" />
<input type="text" name="email" value="Enter email address…" onfocus="this.value=(this.value=='Enter email address…')? '' : this.value ;"/>
</div>
<div class="fl_right">
<input type="submit" name="newsletter_go" id="newsletter_go" value="»"/>
</div>
</fieldset>
</form>
在'echo'後面使用'exit'。如果在重定向之前已經回覆了重定向,則重定向不起作用。 – ThinkingMonkey
@ThinkingMonkey - 絕對,這是工作。這應該是正確的答案。非常感謝你。 – unanswerable
歡迎................. – ThinkingMonkey