1

I am trying to run the Heroku's basic tutorial facebook application (http://devcenter.heroku.com/articles/facebook). Following the instructions, deploying on Heroku went fine. Trying to deploy locally I got the following error

Parse error: syntax error, unexpected ':' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\AppInfo.php on line 36".

I understood there's some problem with the getHome function, found an answer to a similar problem with python here - Problem running Heroku's Facebook app tutorial with Python, but still I am unable to figure it out how it should be done for PHP.

I tried to changed the getHome function to just return http://127.0.0.1:5000/ (like the Site URL I set on my facebook app) but then I get that the browser cannot connect to it.

I have Safari 2.2 running locally, basic Hello world PHP file is running ok.

Thanks in advance.

Community
  • 1
  • 1
Assimiz
  • 256
  • 2
  • 12
  • Can you post the contents of AppInfo.php? atleast the relative part of the code of line #36 – Tjirp Oct 17 '11 at 09:32
  • `return ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?: "http") . "://" . $_SERVER['HTTP_HOST'] . "/";` – Assimiz Oct 17 '11 at 10:00

2 Answers2

0

Looking at your comment what you do there is wrong. It should be

return ($_SERVER['HTTP_X_FORWARDED_PROTO']) ?: "http:" . "://" . $_SERVER['HTTP_HOST'] . "/";
Tjirp
  • 2,435
  • 1
  • 25
  • 35
  • Same error Tjirp. Working locally I do not think I need this code anyway, but just to hard code something. As I wrote above, I tried `return http://127.0.0.1:5000/` but the browser is refusing to go there. It is able to go to http://127.0.0.1, anything special I need to do to make it work with 5000? – Assimiz Oct 19 '11 at 07:31
0

The app is relying on a PHP 5.3 operator to do an "or equals" on that line. It works like this:

$foo ?: "bar";

Which means: assume the value of $foo if set, otherwise "bar". To make that compatible with earlier versions of PHP you'd have to rewrite it using a different operator and functions. Like:

isset($foo) ? $foo : "bar";

So going back to the app, you can fix it with:

$protocol = isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ? $_SERVER['HTTP_X_FORWARDED_PROTO'] : "http";
return $protocol . "://" . $_SERVER['HTTP_HOST'] . "/";

This post has more information on PHP's or equals and alternatives.

Community
  • 1
  • 1
Pedro
  • 2,813
  • 2
  • 22
  • 16
  • Thanks, Pedro. This probably fixed the PHP part of the problem and made it worked instead of using the hardcoded return statement I stated above. However, I am still getting the same error when trying to load the Facebook application. Guess, it is something with the application/Apache settings. – Assimiz Oct 20 '11 at 21:38