~ overflow ~

PHP Script to get HTTP Status number

by z3n on May.08, 2009, under Coding, Tips & Hints Português

Problem:

Getting HTTP Status from a remote page.

Solution:

Problema:

Pegar o código de status de uma página remota.

Solução:

<?php
  1. function cget_info($url) {
  2.  $ch=curl_init();
  3.  @curl_setopt_array($ch,array(
  4.   CURLOPT_URL =&gt; $url,
  5.   CURLOPT_USERAGENT =&gt; "Mozilla/5.0 (Windows NT 5.1) Gecko/2009042316 Firefox/3.0.10",
  6.   CURLOPT_RETURNTRANSFER =&gt; 1,
  7.   CURLOPT_VERBOSE =&gt; false,
  8.   CURLOPT_TIMEOUT =&gt; 5,
  9.   CURLOPT_MAXREDIRS =&gt; 0, // this will catch 302's
  10.   CURLOPT_RETURNTRANSFER =&gt; true,
  11.   CURLOPT_FOLLOWLOCATION =&gt; 1
  12.  ));
  13.  @curl_exec($ch);
  14.  $r=curl_getinfo($ch,CURLINFO_HTTP_CODE);
  15.  curl_close($ch);
  16.  return $r;
  17. }
  18.  
  19. echo cget_info("http://www.overflow.biz"); // 200
  20. echo cget_info("http://www.overflow.biz/dfkjds"); // 404
  21.  
  22. ?&gt;
:, , ,


No comments for this entry yet...

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!