Problem with PHP fopen

  • whos_wee_dug
  • Graduate
  • Graduate
  • User avatar
  • Joined: Apr 28, 2004
  • Posts: 121
  • Loc: Scotland
  • Status: Offline

Post May 25th, 2004, 6:54 am

Hi,

I'm writing this piece of code that is meant to spider a particular page of a website:

PHP Code: [ Select ]
 
<?
 
$url1="http://www.microsoft.com/security/articles/onecomputer.asp";
 
 
 
$handle = fopen($url1, "r");
 
while (!feof($handle))
 
 {
 
   $buffer = fgets($handle, 4096);
 
print $buffer;
 
 
 
}
 
fclose($handle);
 
 
 
?>
 
 
  1.  
  2. <?
  3.  
  4. $url1="http://www.microsoft.com/security/articles/onecomputer.asp";
  5.  
  6.  
  7.  
  8. $handle = fopen($url1, "r");
  9.  
  10. while (!feof($handle))
  11.  
  12.  {
  13.  
  14.    $buffer = fgets($handle, 4096);
  15.  
  16. print $buffer;
  17.  
  18.  
  19.  
  20. }
  21.  
  22. fclose($handle);
  23.  
  24.  
  25.  
  26. ?>
  27.  
  28.  


The problem is that this only works with some pages, the example above doesnt work, i get "We’re sorry, we were unable to service your request. As an option, you may visit any of the pages below for information about Microsoft services and products.". Pages such as http://www.microsoft.com/ do work however.

Why is this?

Thanks in advance,

whos_wee_dug?
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 25th, 2004, 6:54 am

  • whos_wee_dug
  • Graduate
  • Graduate
  • User avatar
  • Joined: Apr 28, 2004
  • Posts: 121
  • Loc: Scotland
  • Status: Offline

Post May 25th, 2004, 7:08 am

Ok...i'm feeling pretty stupid...the acronym RTFM springs to mind...

http://uk2.php.net/manual/en/function.fopen.php

For anyone who cares:

PHP Code: [ Select ]
 
<?
 
$url1="http://www.microsoft.com/security/articles/onecomputer.asp";
 
ini_set('user_agent','MSIE 4\.0b2;');
 
$handle = fopen($url1, "r");
 
while (!feof($handle))
 
 {
 
   $buffer = fgets($handle, 4096);
 
   print $buffer;
 
}
 
fclose($handle);
 
?>
 
 
  1.  
  2. <?
  3.  
  4. $url1="http://www.microsoft.com/security/articles/onecomputer.asp";
  5.  
  6. ini_set('user_agent','MSIE 4\.0b2;');
  7.  
  8. $handle = fopen($url1, "r");
  9.  
  10. while (!feof($handle))
  11.  
  12.  {
  13.  
  14.    $buffer = fgets($handle, 4096);
  15.  
  16.    print $buffer;
  17.  
  18. }
  19.  
  20. fclose($handle);
  21.  
  22. ?>
  23.  
  24.  

whos_wee_dug?

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 201 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.