欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP投票小程序,防超时,防IP限制

程序员文章站 2024-02-08 17:57:04
...
  1. //欢迎访问back.zhizhi123.com
  2. //参考博文http://back.zhizhi123.com/?p=126
  3. set_time_limit(0);//防止超时
  4. function toupiao($i)
  5. {
  6. $proxy = array('182.48.116.51:8080','110.177.63.191:9999','221.10.40.238:80','221.10.40.236:83','221.10.40.237:80','221.10.102.199:82','42.121.0.247:9999','42.121.28.111:3128','117.135.194.139:80','119.147.91.21:80','58.247.109.243:80','118.233.36.246:8585');
  7. $url = "http://www.example.com/tea/love.php";
  8. $ch = curl_init();
  9. $data = array (
  10. 'id' => '13'
  11. );
  12. //设置来源地址,如果不设置,论坛服务器有可能有验证不允许回复
  13. curl_setopt($ch,CURLOPT_REFERER,"http://www.example.com/tea/index.php?m=content&c=index&a=lists&catid=10");
  14. //能保存cookie
  15. curl_setopt($ch,CURLOPT_COOKIESESSION,true);
  16. curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
  17. curl_setopt($ch, CURLOPT_PROXY, $proxy[$i]);
  18. curl_setopt($ch, CURLOPT_POST, 1);
  19. curl_setopt($ch, CURLOPT_HEADER, 0);
  20. curl_setopt($ch, CURLOPT_URL,$url);
  21. //为了支持cookie
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  23. $result = curl_exec($ch);
  24. if(curl_errno($ch))
  25. {
  26. echo 'Curl error: ' . curl_error($ch);
  27. }
  28. }
  29. for($i=0;$i
  30. {
  31. echo "begin 第".$i."次投票";
  32. toupiao($i);
  33. echo 'end';
  34. echo "";
  35. }
复制代码

PHP