View Single Post
Old 05-22-2008, 10:29 PM  
GrouchyAdmin
Now choke yourself!
 
GrouchyAdmin's Avatar
 
Industry Role:
Join Date: Apr 2006
Posts: 12,085


This one's stupid, but it uses the common class.curl.php, and does a select based upon the error, so you can add different features/functions for 403s, 500s, etc.. Mostly, I'm just lazy and didn't figure it deserved OOP, even if I'm using an OOP class. Enjoy.

Code:
<html>
<head>
<Title>404 Test Thingy or whatever</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff">
<br>
<form method="post">
  <div align="center"><strong>Test URLs:</strong><br>
      <textarea name="urls" id="urls" cols="45" rows="5"><?=isset($_REQUEST['urls'])?$_REQUEST['urls']:"";?></textarea>
    <br>
    <input type="submit" name="submit" id="submit" value="Check Response">
  </div>
</form>
<?php
// This is hardly an example of good PHP.  Ugh.
@require_once("class.curl.php");
// trim() to get rid of errant enter keys.
$myurls = (isset($_REQUEST['urls'])?explode("\n", trim($_REQUEST['urls'])): array());
foreach ($myurls as $url) {
  // use our cURL class.
  $curlInit = new curl($url);
  // Make sure we don't follow redirects.
  $curlInit->setopt(CURLOPT_FOLLOWLOCATION, FALSE) ;
  // Do it.
  $curlInit->exec();
  // If we returned a connection error, say so.
  if ($myError = $curlInit->hasError()) {
    echo "ERR: $url ($myError)<br>\n";
  } else {
    // Reinit our array
    $status = array();
    // Seems to have worked, parse it.
    if (is_array($curlInit->m_status))
      $status = $curlInit->m_status;
    // Simple error checking.
    if (!empty($status)) {
      switch($status["http_code"]) {
        case "404":
           echo "<font color='red'>404</font>: <a href='$url' target='_new'>[link]</a> $url<br>\n";
           break;
        default:
           // Do nothing if not 404, I guess.
           break;
      }
    }
  }
  // We're done, close the socket.
  $curlInit->close();
} ?>
</body>
</html>
__________________

Last edited by GrouchyAdmin; 05-22-2008 at 10:31 PM.. Reason: rooka rike dis
GrouchyAdmin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote