title: curl request returning wrong response code
body: <p>I am having a need of getting http response code for page urls from sitemap.xml file. When i get the response code by my cron process it returns 403 (Known as access forbidden : though i can access the passed url from browser). </p>
  
  <p>But if I run the same code from my localhost, it returns the correct http response code (i.e 200).</p>
  
  <p>Why is the difference in returning different http response code from local host and from server ?? How to resolve the problem ?</p>
  
  <p>The code for extracting the http response code is as below.</p>
  
  <pre><code>function check_response_code() {
      $pageurl='http://www.certona.com/online-merchandising/';
      $trimurl = '';
      $start = '';
      $end = '';
      $total = '';
  
      $start = microtime(true);
      $response_code = '';
      if (!stristr($pageurl, "http://"))
      {
          if (!stristr($pageurl, "https://"))
          {
              $trimurl = "http://" . $pageurl;
          } else
          {
              $trimurl = $pageurl;
          }
      } else
      {
          $trimurl = $pageurl;
      }
      $curl = curl_init();
      //don't fetch the actual page, you only want headers
  
      curl_setopt($curl, CURLOPT_URL, $trimurl);
      curl_setopt($curl, CURLOPT_NOBODY, true);
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_FILETIME, true);
  
      $result = curl_exec($curl);
  
      $timestamp = curl_getinfo($curl, CURLINFO_FILETIME);
      $response_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
      $mime_type = curl_getinfo($curl, CURLINFO_CONTENT_TYPE);
      $end = microtime(true);
      $total = round($end - $start, 5);
  
      if ($timestamp != -1)
      { //otherwise unknown
          $arr=array(date("Y-m-d H:i:s", $timestamp), $response_code, $total, $mime_type); //etc
      } else
      {
          $arr=array("", $response_code, $total, $mime_type);
      }
      echo "&lt;pre&gt;";
      print_r($arr);
      echo "&lt;/pre&gt;";
  }
  </code></pre>
  
  <p>Thank you.. </p>