0

我有一个联系表格,位于:siteurl.com/help/contact 当他们点击发送按钮时,他们会被发送到一个页面:siteurl.com/ext/contact/contactpost.php - 这会将表格发送到电子邮件。

但是,在 mail() 函数之后,我使用标头直接将它们发送回 siteurl.com/help/contact,如果它们来自 siteurl.com/ext/contact/contactpost.php,我希望它在其中显示警报

我目前有这个(URL 会改变,所以使用 $_SERVER['SERVER_NAME']):

$url = "http://". $_SERVER['SERVER_NAME'] . "/ext/contact/contactpost.php";
if( $_SERVER['HTTP_REFERER'] == $url ){

    // The user was referred by the correct page, so you're good to go
    alert('Thanks, your message was submitted!');

}

回显 $url 给了我正确的 siteurl.com/ext/contact/contactpost.php 但没有警报!

有什么帮助吗?

4

1 回答 1

1

警报不是 PHP 函数,而是一个 javascript 函数(客户端不是服务器端)!

修复代码:

$url = "http://". $_SERVER['SERVER_NAME'] . "/ext/contact/contactpost.php";
if( $_SERVER['HTTP_REFERER'] == $url ){

    // The user was referred by the correct page, so you're good to go
    echo "<script language='javascript' type='text/javascript'>";
     echo "alert('Thanks, your message was submitted!');";
    echo "</script>";


}
于 2013-01-28T18:38:16.717 回答