file_get_contents被屏蔽解决方法

在php中file_get_contents函数可直接采集远程服务器内容,然后保存到一个变量中了,介理一般都会把file_get_contents、fsockopen等一些IO操作的函数禁用掉,因为它们怕被 DDOS.

那么一般情况下,我们改不了服务器的 inc.php,只能自己写一套IO来代替上面的PHP函数了,代码如下:

$url = file_get_contents('http://www.phpfensi.com/');

我们可以用下面的代码代替:

  1. //禁用file_get_contents的解决办法  
  2. $ch = curl_init();  
  3. $timeout = 10; // set to zero for no timeout  
  4. curl_setopt ($ch, CURLOPT_URL,'http://www.hzhuti.com/');  
  5. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);   
  6. curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
  7. $url = curl_exec($ch); 

curl是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP、FTP、TELNET等,它不会被服务器禁用,所以我们可以用来模拟file_get_contents一样打开一条URL.

利用function_exists函数来判断php是否支持一个函数可以轻松写出下面函数

  1. <?php  
  2.  function vita_get_url_content($url) {  
  3.  if(function_exists('file_get_contents')) {  
  4.  $file_contents = file_get_contents($url);  
  5.  } else {  
  6.  $ch = curl_init();  
  7.  $timeout = 5;   
  8.  curl_setopt ($ch, CURLOPT_URL, $url);  
  9.  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);   
  10.  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
  11.  $file_contents = curl_exec($ch);  
  12.  curl_close($ch);  
  13.  }  
  14.  return $file_contents;  
  15.  }  
  16.  ?> 
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » file_get_contents被屏蔽解决方法

190 评论

  1. indocin 50mg us indocin brand trimox 250mg over the counter

  2. buy zyloprim online zyloprim order order generic zetia

  3. best casino cialis for sales order tadalafil 10mg without prescription

  4. tretinoin cream price avana tablet buy avanafil 200mg pills

  5. coupon for cialis Cialis delivery best play money poker sites

  6. benicar 20mg us order calan purchase depakote pill

  7. asacol 400mg drug avapro medication purchase avapro without prescription

  8. Психоаналитическое лечение строится таким образом, что сначала
    психоаналитик помогает пациенту найти путь для его вытесненных воспоминаний.
    После внимательного наблюдения за больным и анализа угадываются различные детали и излагаются больному.

    Предполагается, что эти наблюдения
    отзовутся в сознании человека
    и сделают осознанными отдельные
    проявления бессознательного. Почему я потеряла интерес к жизни?

  9. prednisolone 40mg for sale lasix 100mg for sale furosemide 40mg without prescription

  10. order generic methotrexate 2.5mg reglan where to buy buy metoclopramide pills for sale

  11. quetiapine/seroquel 100 mg wiki seroquel pisa syndrome during treatment with quetiapine and risperidone

  12. dosages of zoloft zoloft in teens is sertraline a tricyclic antidepressant

  13. buy generic fluconazole for sale diflucan online buy ciprofloxacin 500mg over the counter

  14. order leflunomide 10mg arava 10mg oral azulfidine 500mg canada

  15. buy vardenafil 10mg for sale tizanidine tablet buy plaquenil 400mg pill

  16. how to get amlodipine without a prescription cheap prilosec 10mg order omeprazole 10mg pills

  17. how to get metoprolol without a prescription metoprolol us medrol cheap

  18. order sildenafil 100mg generic estrace 2mg pill order estrace for sale

  19. lamictal without prescription lamotrigine pills order minipress 1mg for sale

  20. keflex allergy alternative web md, keflex keflex with or without food

  21. amoxicillin 500mg?? amoxicillin 875 how much is amoxicillin at walgreens

  22. ampicilina o amoxicilina/ГЎcido clavulГЎnico (augmentin) augmentin 3 day course nuvaring und augmentin

  23. fexofenadine order allegra price amaryl over the counter

  24. safer alternative to ciprofloxacin ciprofloxacin dogs ciprofloxacin 500 mg no prescription

  25. calcitriol 0.25 mg ca tricor canada order fenofibrate online cheap

  26. where to buy azithromycin over the counter azithromycin dairy azithromycin with amoxicillin

  27. buy generic combivir online zidovudine sale accupril over the counter

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡