如何从php中检测阻止的地址 [英] how to detect blocked address from within php

查看:80
本文介绍了如何从php中检测阻止的地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的问题;我们正试图在我们的网站上设置facebook like和twitter tweet按钮,但是当Facebook和Twitter在他们的计算机上被阻止时,它会导致浏览器无响应。
所以我想做的是检测facebook或twitter是否被阻止,然后删除这些计算机的按钮,同时允许所有其他人加载它们。

so here is my problem; we are trying to setup the facebook like and twitter tweet button on our website but it is causing browsers to become unresponsive when facebook and twitter are blocked on their computers. so what i would like to do is detect if facebook or twitter are blocked and then remove the buttons for those computers, while allowing all others to load them.

这可能在php或javascript中吗?

is this possible in php or in javascript?

如果链接被阻止,我无法找到有关测试的任何信息。

i haven't been able to locate any information about testing if a link is blocked or not.

推荐答案

您可以在页面上放置两个隐藏的图像,然后即时添加类似按钮。

类似这应该有效:

You could put two hidden images on you page and have then add the like-buttons on the fly.
Something like this should work:

<img style="display:none;"
  onload="user_can_access_facebook()"
  onerror="no_access_to_facebook()"
  src="http://static.ak.fbcdn.net/rsrc.php/v1/yp/r/kk8dc2UJYJ4.png" />

javascript函数 user_can_access_facebook()应该在哪里将相似按钮添加到DOM。

Where the javascript function user_can_access_facebook() should add the like-button to the DOM.

http://static.ak.fbcdn.net/rsrc.php/v1/yp/r/ kk8dc2UJYJ4.png 是登录页面上Facebook徽标的网址。这可能不是静态链接,因此您可能需要查找其他一些静态资源进行检查。)

(http://static.ak.fbcdn.net/rsrc.php/v1/yp/r/kk8dc2UJYJ4.png is the url to the Facebook logo on the login page. This might not be a static link so you might need to find some other static resource to check against.)

对于Twitter你也应该这样做。

For twitter you should do the same.

编辑:

我把一个小的放在一起POC:


I put together a small POC:

<html>
  <head>
    <script language="javascript" type="text/javascript">
      function user_can_access(sitename) {
        var siteDiv = document.getElementById(sitename + '_access');
        siteDiv.innerText = "You have access to " + sitename;
      }

      function no_access(sitename) {
        var siteDiv = document.getElementById(sitename + '_access');
        siteDiv.innerText = "You do NOT have access to " + sitename;
      }
    </script>
  </head>
  <body>
    <img src="http://static.ak.fbcdn.net/rsrc.php/v1/yp/r/kk8dc2UJYJ4.png"
      onload="user_can_access('Facebook')"
      onerror="no_access('Facebook')"
      style="display:none;" />
    <img src="http://support.twitter.com/images/twitter-logo-no-bird.png"
      onload="user_can_access('Twitter')"
      onerror="no_access('Twitter')"
      style="display:none;" />

    <div id="Facebook_access"></div>
    <div id="Twitter_access"></div>
  </body>
</html>

在本地尝试只是阻止访问上面的相应域名(static.ak.fbcdn.net
和support.twitter.com)。

如前所述,您可能需要找到一些静态的其他资源来检查。如果图像的网址在Facebook和Twitter上发生变化,那么您必须在代码中更改它。

To try it out locally just block access to the respective domain above (static.ak.fbcdn.net and support.twitter.com).
As stated before you might need to find some other resources that are static to check against. If the urls' to the images change on facebook and twitter then you must change it in your code aswell.

这篇关于如何从php中检测阻止的地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆