简体   繁体   中英

How to configure Heroku's Facebook tutorial app to run locally with PHP?

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.

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM