如果来自 url,则显示警报

Display alert if came from url

本文关键字:显示 url 如果      更新时间:2023-09-26

>我有一个联系表格位于: 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 但没有警报!

有什么帮助吗?

警报不是一个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>";

}