1

I wrote a PHP script to retrieve my Google reviews and it works fine on my Wamp server. However when I moved it to my actual host I get this error:

Warning: file_get_contents(https://maps.googleapis.com/maps/api/place/details/json?reference=CoQBeAAAAK9bAE7g15Db0Xl4lmd371L8qLBpPHitJl7iI9GT6LYS0BheLRQZzvKXqNHevt08DH0fB7inlvcLby83yUSjzNeH5-n41HxtC60tYG9bE-B15PbShGHnQpy3wsvOoOsRtjmOCnEiaSmlsSWgM2hypXcEeHjh2NiFSXVbEo8pVTRXEhCZSqsHiAEWHhOflDaqXP9oGhQU8WS8PRwxFf7IaiPLWfxaA69csw&sensor=true&key=mykey) [function.file-get-contents]: failed to open stream: Permission denied in /home/www/advancedcomputing.us/reviews.php on line 8

I set permissions to 777 on reviews.php, but still same error. Obviously it's storing the data in a file that I don't have access to, but I have no idea which file that is. Any help would be appreciated.

Here is the code:

<style>
.text{font-size:8pt;color:black;font-weight:normal;font-family:arial}
.name{font-size:10pt;color:black;font-weight:bold;font-family:arial}
</style>

<?php
$url = "https://maps.googleapis.com/maps/api/place/details/json?reference=CoQBeAAAAK9bAE7g15Db0Xl4lmd371L8qLBpPHitJl7iI9GT6LYS0BheLRQZzvKXqNHevt08DH0fB7inlvcLby83yUSjzNeH5-n41HxtC60tYG9bE-B15PbShGHnQpy3wsvOoOsRtjmOCnEiaSmlsSWgM2hypXcEeHjh2NiFSXVbEo8pVTRXEhCZSqsHiAEWHhOflDaqXP9oGhQU8WS8PRwxFf7IaiPLWfxaA69csw&sensor=true&key=mykey";
//$jsonfile= file_get_contents($url);

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept-Language: en-us'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$jsonfile = curl_exec($ch);
curl_close($ch);
$data = json_decode($jsonfile);


$data = json_decode($jsonfile);

echo "<table cellpadding=0 cellspacing=0 width=250 border=0 bgcolor=white><tr><td align=center valign=bottom><a href=https://plus.google.com/114172317884481430965/about?hl=en style=color:blue;font-size:8pt;font-family:arial;>see all reviews</a></td></tr><tr><td height=5></td></tr>";

for($x=0;$x<sizeof($data->result->reviews);$x++){
echo "<tr>";
echo "<td class=name class=text style=padding-left:15px;>";
echo $data->result->reviews[$x]->author_name;
echo "&nbsp;&nbsp;";
echo date("m-d-Y", $data->result->reviews[$x]->time);
echo "</td></tr><tr><td class=text style=padding-left:15px;>";
if($data->result->reviews[$x]->rating==5){echo "<img src=star.png><img src=star.png><img src=star.png><img src=star.png><img src=star.png>";}
if($data->result->reviews[$x]->rating==4){echo "<img src=star.png><img src=star.png><img src=star.png><img src=star.png>";}
if($data->result->reviews[$x]->rating==3){echo "<img src=star.png><img src=star.png><img src=star.png>";}

echo "</td></tr><tr><td class=text style=padding-left:15px;>";
echo $data->result->reviews[$x]->text;
echo "</td></tr>";
echo "<tr><td height=15></td></tr>";
}
?>
</table>
rerat
  • 321
  • 3
  • 14
  • 3
    Does your host have `allow_url_fopen` enabled in php.ini? – Barmar Jan 10 '14 at 03:03
  • not sure, can I test with phpinfo()? – rerat Jan 10 '14 at 03:04
  • 3
    The error is occurring in `file_get_contents()` - i.e. while your script is trying to read the file. Changing permissions on your script will have no effect on this, nor will changing permissions on your target folder. Does your host have `allow_url_open` enabled? If not, this won't work and you might have to use `cURL`. –  Jan 10 '14 at 03:06
  • http://stackoverflow.com/questions/13433660/how-to-check-if-allow-url-fopen-is-enabled-or-not – Barmar Jan 10 '14 at 03:06
  • Yes it is, here is my phpinfo(): allow_url_fopen On On – rerat Jan 10 '14 at 03:06
  • What user is owner of your file? – Rafael Soufraz Jan 10 '14 at 03:10
  • possible duplicate of [php file\_get\_contents returns null when allow\_url\_fopen is on](http://stackoverflow.com/questions/10354805/php-file-get-contents-returns-null-when-allow-url-fopen-is-on) – Mike Jan 10 '14 at 03:11
  • You will have to use cURL –  Jan 10 '14 at 03:24
  • Is your host running with PHP in safe mode? If so, it won't work. – Travis Pessetto Jan 10 '14 at 03:40
  • Did some testing. Safe mode is off, not sure how to check ownership using the file manager on my host. Tried curl, but now I just get nothing, no error or data. Added curl code to post in case I did it wrong. – rerat Jan 11 '14 at 00:26
  • I can't figure it out and now one seems to know whats up, so i just moved it to a different host and it works fine. – rerat Jan 12 '14 at 05:11

0 Answers0