Checking proxy script

Finally, the last part of the post. Get ready for some “serious” programming.

  1. Include whatismyip.php. Don’t forget to specify URL.
  2. Copy getPage function to proxychecker.php or include it as a file.
  3. Specify a time limit.
  4. Write getProxies() function.
  5. Write deleteProxy($proxy) function.
  6. Specify badvars.php URL.
  7. Specify sleep intervals.
  8. Test and fix proxychecker.php. You don’t need to upload the script to a server. You can use your PC for testing.
  9. Deploy the script. Don’t use the same host for badvars.php and proxychecker.php.
  1. <?php
  2. /*
  3. * TODO 1
  4. * Include whatismyip.php. Don’t forget to specify URL.
  5. *//*
  6. * TODO 2
  7. * Copy getPage (http://www.fromzerotoseo.com/scraping-websites-php-curl-proxy/)
  8. * here or include it as a file.
  9. */set_time_limit(/* TODO 3 specify a time limit */);function getProxies() {
  10. /*
  11. * TODO 4
  12. * Load proxies from a file or database.
  13. * Return array of [IP]:[port] proxies or NULL.
  14. */
  15. }function deleteProxy($proxy) {
  16. /*
  17. * TODO 5
  18. * Delete $proxy from file/database or
  19. * mark as ‘bad’.
  20. */
  21. }
  22.  
  23. $whatIsMyIp = new WhatIsMyIp();
  24. $myIpAddress = $whatIsMyIp->getServerIpAddress();
  25. if (empty($myIpAddress)) {
  26. echo("Can’t obtain IP address\n");
  27. exit();
  28. }
  29.  
  30. $proxies = getProxies();
  31. if (empty($proxies)) {
  32. echo("Can’t load proxies\n");
  33. exit();
  34. }
  35.  
  36. foreach ($proxies as $proxy) {
  37. $result = getPage(
  38. $proxy,
  39. /*
  40. * TODO 6
  41. * Specify badvars.php URL
  42. */,
  43. ‘http://www.google.com/’,
  44. ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8′,
  45. 1,
  46. 5);
  47.  
  48. if (empty($result[‘ERR’])) {
  49. if (preg_match("/" . $myIpAddress . "/", $result[‘EXE’])) {
  50. deleteProxy($proxy);
  51. } else {
  52. /*
  53. * Good proxy!
  54. */
  55. }
  56. } else {
  57. echo($result[‘ERR’] . ‘\n’);
  58. deleteProxy($proxy);
  59. }
  60.  
  61. sleep(rand(/* TODO 7 [int] */, /* [int] */));
  62. }
  63. ?>
Sponsor links

Tags: , , , ,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

AddThis Social Bookmark Button
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4 out of 5)
Loading ... Loading ...

Leave a Reply

Random Articles