CURL – Get HTTP Status code

$baseUrl = '';

function checkHttpStatusCode($url='')
 global $baseUrl;
 $url = $baseUrl.$url.'/';
 //echo "{$url}<br>";

 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_HEADER, true); // we want headers
 curl_setopt($ch, CURLOPT_NOBODY, true); // we don't need body
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_TIMEOUT,10);
 $output = curl_exec($ch);
 $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//echo 'HTTP code: ' . $httpcode;
 return $httpcode;

$listDir = array('dir1','dir2');

foreach ($listDir as $key => $value) {
 $code = checkHttpStatusCode($value);
 if ($code == '200') {
 //echo $code.'=>'.$value.'<br>';
 echo $baseUrl.$value.'/<br>';

Published by


Hello, I am a software developer from Bangladesh. I develop professional web sites/applications using LAMP(Linux, Apache, MySql, PHP) Stack. I have 7 years of professional working experience developing websites on WordPress, Magento, Laravel, Yii, Code Igniter. I have in depth knowledge on following language and tools, PHP, C, C++, Java, MySql, HTML(5), CSS(3), JavaScript, jQuery, Linux, Windows, Apache, Ngnix.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s