--- Ben Farhner <[EMAIL PROTECTED]> wrote:

> ok i need to check a url to make sure it works, and if it does, 
> then i want to print out "online", and if it returns 404 then i 
> want to print out "offline". how do i check if the url works or 
> not? thanks

An easy way to do it is to grab the Snoopy class
(http://snoopy.sourceforge.net), include it in your script, and use the
following:

-----
include_once 'Snoopy.class.inc';

function check_link($url) {
  $snoopy = new Snoopy;
  $snoopy->fetch($url);

  // a response code of 404 means that the file was not found
  if (intval($snoopy->response_code == 404) {
    return(false);
  } else {
    return(true);
  }
}
------

You could also check for other codes (550, etc.) using a
switch(intval($snoopy->response_code) and setting different notices for
the results.

HTH.

-Bob

(Source: PHP Developer's Cookbook, SAMS Publishing)


        
                
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/HKFolB/TM
--------------------------------------------------------------------~-> 

Community email addresses:
  Post message: php-list@yahoogroups.com
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to