为什么 ping 属性在 html5 中无法正常工作

Why ping attribute not working correctly in html5

您好,我正在为我的项目构建一个跟踪系统,我尝试使用 ping 属性,但该属性在 localhost.

上无法正常工作

这是我的代码 php

echo "<a href='".$r_url."' ping='/redirect?url=".$r_url."'>";

谁能告诉我这段代码有什么问题。

根据您的 post 和您在评论中提供的信息,您正试图通过 ping 属性中的 link 进行重定向。

W3C documentation:

The ping attribute specifies a list of URLs to be notified if the user follows the hyperlink.

这意味着用户不会直接重定向到此 URL,而是会发生这种情况:

  1. 用户点击 link
  2. 浏览器向ping属性中的URL发送POST请求
  3. 浏览器将用户重定向到 href 属性中的 URL

如果您想通过 URL 重定向,只需将您的重定向 URL 放在 href 属性中:

echo "<a href='/redirect?url=".$r_url."'>";

我希望你得到这个答案还不算太晚:

您应该使用 $_SERVER 而不是 $_POST