【问题标题】:Display alert if came from url如果来自 url,则显示警报
【发布时间】:2013-01-29 02:45:41
【问题描述】:

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

有什么帮助吗?

【问题讨论】:

  • Alert 不是 PHP 函数,除非你自己创建了它,PHP != JavaScript。
  • 这个 PHP 页面是如何显示的?如果它显示在屏幕上,你可以试试echo "<script>alert('javascript alert');</script>"
  • 是的,那里有一个大笨蛋,我的错!干杯。

标签: php javascript alert


【解决方案1】:

Alert 不是 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>";


}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 2015-08-16
    • 1970-01-01
    相关资源
    最近更新 更多