我创建了一个商店取景器3个月前的一个网站,将数据存储在数据库中。 在他们的邮政编码的用户类型,当你点击搜索他们列出最近的商店给他们。
当我今天早上测试的现场直播我让PHP错误messag:
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(http://maps.google.co.uk/maps/geo?q=sr3+4as&output=json&key=----MYKEY---): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
Filename: controllers/store.php
当我想这在临时站点和我的本地我得到同样的回应! 现在,我还没有触及代码为6个月,所以我认为我的钥匙已经过期或损坏。 我创建了一个新的API密钥和我的头,并在那里说的错误是 - 没有运气控制器添加此。
我要去哪里错了? 有什么东西停止请求,并不能确定其中的问题是?
这里是我的代码控制器:
class Store extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('store_model');
$this->load->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->form_validation->set_rules('postcode','Postcode','required|trim|htmlspecialchars|xssclean');
$this->form_validation->set_error_delimiters('<div id="errors">• ','</div>');
if($this->form_validation->run() == FALSE) {
$data['error'] = 1;
if($this->input->post('submit')) {
$data['error_msg'] = "Please enter a Post Code.";
}
} else {
$data['error'] = 0;
if($this->input->post('postcode')) {
$postCodeClean = formatBritishPostcode($this->input->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->input->post('postcode'))."&output=json&key=---MYKEY---";
$json = file_get_contents($url);
$store_data = json_decode(str_replace(""","\"",htmlentities($json)));
$lng = $store_data->Placemark[0]->Point->coordinates[0];
$lat = $store_data->Placemark[0]->Point->coordinates[1];
$data['stores'] = $this->store_model->get_stores($lat, $lng);
}
}
}
$this->load->view('template', $data);
}
}