title: HTTP request failed! HTTP/1.0 403 Forbidden
body: <p>I created a store finder 6 months ago for a site and the data is stored in the database. The user types in their postcode and when you click search they list the nearest stores to them.</p>
  
  <p>When i tested the live site this morning i get php error messag:</p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: Warning
  
  Message: file_get_contents(http://maps.google.co.uk/maps/geo?q=sr3+4as&amp;output=json&amp;key=----MYKEY---): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
  
  Filename: controllers/store.php
  </code></pre>
  
  <p>When i tried this at the staging site and my localhost i get the same response! Now i havent touched the code for 6 months so i assumed that my key had expired or corrupted. I created a new API key and added this in my header and in the controller where it says the error is -no luck.</p>
  
  <p>Where am i going wrong?! Something is stopping the request and unsure where the issue is?</p>
  
  <p>Here is my controller with the code:</p>
  
  <pre><code>class Store extends CI_Controller {
  
      function __construct() {
          parent::__construct();
          $this-&gt;load-&gt;model('store_model');
          $this-&gt;load-&gt;library('form_validation');
      }
  
      public function index(){
          $data['page_title'] = "Store Finder";
          $data['section_no'] = 5;
          $data['content'] = "store";
  
           function formatBritishPostcode($postcode) {    
              //--------------------------------------------------
              // Clean up the user input
  
              $postcode = strtoupper($postcode);
              $postcode = preg_replace('/[^A-Z0-9]/', '', $postcode);
              $postcode = preg_replace('/([A-Z0-9]{3})$/', ' \1', $postcode);
              $postcode = trim($postcode);
  
              //--------------------------------------------------
              // Check that the submitted value is a valid
              // British postcode: AN NAA | ANN NAA | AAN NAA |
              // AANN NAA | ANA NAA | AANA NAA
  
              if (preg_match('/^[a-z](\d[a-z\d]?|[a-z]\d[a-z\d]?) \d[a-z]{2}$/i', $postcode)) {
                  return $postcode;
              } else {
                  return NULL;
              }       
          } 
  
          $this-&gt;form_validation-&gt;set_rules('postcode','Postcode','required|trim|htmlspecialchars|xssclean'); 
          $this-&gt;form_validation-&gt;set_error_delimiters('&lt;div id="errors"&gt;&amp;bull;&amp;nbsp;','&lt;/div&gt;');
  
          if($this-&gt;form_validation-&gt;run() == FALSE) {
              $data['error'] = 1;
              if($this-&gt;input-&gt;post('submit')) {
                  $data['error_msg'] = "Please enter a Post Code.";   
              }
          } else {
              $data['error'] = 0;
              if($this-&gt;input-&gt;post('postcode')) {
                  $postCodeClean = formatBritishPostcode($this-&gt;input-&gt;post('postcode'));
                  if ($postCodeClean === NULL) {
                      $data['error_msg'] = "Please supply a valid Post Code.";
                  } else {
  
                  $url = "http://maps.google.co.uk/maps/geo?q=".urlencode($this-&gt;input-&gt;post('postcode'))."&amp;output=json&amp;key=---MYKEY---";
  
                      $json = file_get_contents($url);
                      $store_data = json_decode(str_replace("&amp;quot;","\"",htmlentities($json)));
  
                      $lng = $store_data-&gt;Placemark[0]-&gt;Point-&gt;coordinates[0];            
                      $lat = $store_data-&gt;Placemark[0]-&gt;Point-&gt;coordinates[1];
  
                      $data['stores'] = $this-&gt;store_model-&gt;get_stores($lat, $lng);
                  }
              }
          }
  
          $this-&gt;load-&gt;view('template', $data);
      }
  } 
  </code></pre>