dongxun8189 2013-01-17 05:15
浏览 25
已采纳

如果无法访问互联网,则显示静态图像

I am working on a college website. I'm using a Facebook plugin to show the likes of a Facebook page by using this:

<iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fpcclahore&amp;width=364&amp;height=220&amp;show_faces=true&amp;colorscheme=light&amp;stream=false&amp;border_color&amp;header=true" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:364px; height:220px;" allowTransparency="true"></iframe>

The problem is that Facebook is blocked on the college servers, so nothing appears except a warning. Is it possible to show a static image instead of Facebook plugin while the internet not available (localhost) or Facebook not accessible? Like this:

if(Facebook accessible)
show Facebook pluging
else
<img src="images/fb.jpg" width="364" height="220">
  • 写回答

4条回答 默认 最新

  • dtgj8529 2013-01-17 05:52
    关注
    // check if local server is HTTPS if so check Facebook HTTPS
    $remote = ('80' !== $_SERVER['SERVER_PORT'])
        ? array('host' => 'ssl://www.facebook.com', 'port' => 443)  // HTTPS Facebook
        : array('host' => 'www.facebook.com', 'port' => 80);        // HTTP Facebook
    
    $fp = @ fsockopen($remote['host'], $remote['port'], $errno, $errstr, 5);
    
    echo (!$fp) // check if failed
        ? '<img src="images/fb.jpg" width="364" height="220">' // output local image
        : '<iframe src="//www.facebook.com/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2Fpcclahore&amp;width=364&amp;height=220&amp;show_faces=true&amp;colorscheme=light&amp;stream=false&amp;border_color&amp;header=true" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:364px; height:220px;" allowTransparency="true"></iframe>'; // output IFRAME
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用