简体   繁体   English

如何配置Heroku的Facebook教程应用程序以通过PHP在本地运行?

[英]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 ). 我正在尝试运行Heroku的基本教程facebook应用程序( http://devcenter.heroku.com/articles/facebook )。 Following the instructions, deploying on Heroku went fine. 按照说明进行操作,在Heroku上进行部署就可以了。 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". 解析错误:语法错误,第36行上的C:\\ Program Files \\ Apache Software Foundation \\ Apache2.2 \\ htdocs \\ AppInfo.php中出现意外的':'。

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. 我知道getHome函数存在一些问题,在这里找到了与python类似问题的答案-使用Python 运行Heroku的Facebook应用程序教程时出现问题 ,但我仍然无法弄清楚应该如何为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. 我试图将getHome函数更改为仅return http://127.0.0.1:5000/ (例如我在我的facebook应用程序上设置的站点URL),但是随后我发现浏览器无法连接到它。

I have Safari 2.2 running locally, basic Hello world PHP file is running ok. 我有在本地运行的Safari 2.2,基本的Hello world PHP文件运行正常。

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. 该应用程序依靠PHP 5.3运算符在该行上执行“等于”操作。 It works like this: 它是这样的:

$foo ?: "bar";

Which means: assume the value of $foo if set, otherwise "bar". 这意味着:假设设置了$ foo的值,否则为“ bar”。 To make that compatible with earlier versions of PHP you'd have to rewrite it using a different operator and functions. 为了使其与早期版本的PHP兼容,您必须使用其他运算符和函数将其重写。 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. 这篇文章有更多关于PHP或equals和Alternatives的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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