我在 GitHub 上下载了某人的项目,该项目使 Facebook 用户能够相互发送比特币。他一年前放弃了开发,我想构建自己的应用程序,但我目前正在查看他的代码并尝试设置我的开发环境。
我有点理解 PHP,它意味着服务器端脚本,JavaScript 在客户端机器上执行(全部在浏览器中,Node.js 是一个服务器端框架)
无论如何,他正在做一些奇怪的事情,并且会产生错误。
目录结构如下:
inc/
init.php
app.php
btc.php
index.php
settings.php
还有更多文件,但我认为以上就足够了。
所以我运行命令“php -S localhost:8000”并启动服务器
我转到本地主机,页面呈现后我在终端中收到这些错误:
[Sat Apr 12 02:23:11 2014] PHP Notice: Undefined variable: app_url in /home/arthur/projects/bfb/index.php on line 21
[Sat Apr 12 02:23:11 2014] PHP Notice: Undefined variable: callback_url in /home/arthur/projects/bfb/index.php on line 22
[Sat Apr 12 02:23:11 2014] PHP Fatal error: Call to undefined function get_x_rates() in /home/arthur/projects/bfb/index.php on line 23
[Sat Apr 12 02:23:11 2014] 127.0.0.1:59511 [200]: / - Call to undefined function get_x_rates() in /home/arthur/projects/bfb/index.php on line 23
[Sat Apr 12 02:23:11 2014] 127.0.0.1:59512 [200]: /stylesheets/reset.css
[Sat Apr 12 02:23:11 2014] 127.0.0.1:59513 [200]: /stylesheets/btc.css
[Sat Apr 12 02:23:11 2014] 127.0.0.1:59514 [200]: /javascript/chosen.css
[Sat Apr 12 02:23:21 2014] 127.0.0.1:59515 Invalid request (Unexpected EOF)
[Sat Apr 12 02:23:21 2014] 127.0.0.1:59516 Invalid request (Unexpected EOF)
index.php 文件具有以下一般结构:
<?php
//error_reporting(E_ALL);
//ini_set("display_errors", 1);
require 'settings.php';
require 'inc/btc.php';
require 'inc/app.php';
require 'inc/init.php';
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<meta charset="utf-8" />
<title>Bitcoin Transactions</title>
<link rel="stylesheet" href="stylesheets/reset.css" type="text/css" />
<link rel="stylesheet" href="stylesheets/btc.css" type="text/css" />
<link rel="stylesheet" href="javascript/chosen.css" type="text/css" />
<script>var appurl='<?=$app_url?>',
hosturl='<?=$callback_url?>',
rates=<?=get_x_rates()?>;</script>
<script type="text/javascript" src="javascript/jquery-1.7.1.min.js"> </script>
<script type="text/javascript" src="javascript/chosen.jquery.min.js"></script>
<script type="text/javascript" src="javascript/btc.js"></script>
</head>
<body>
....
</body>
</html>
既然他在html文件的开头加载PHP文件,为什么它看不到我在这个settings.php文件中定义的变量:
<?
$bucket_addr='-taken-out-for-Stack-Overflow';
$callback_url='https://super-lame-name-1231232.herokuapp.com/';
$app_url='https://apps.facebook.com/c------------------n';
$blockchain_guid="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
$blockchain_pw="xxxxxxxxxxxxxxxx";
$fb_settings=array(
'appId' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
);
$fb_tx_fee=10000; //in satoshi (0.0001 BTC)
$btc_tx_fee=50000; //in satoshi (0.0005 BTC)
$tx_per_page=10;
$revert_duration="60 days";
感谢您的帮助!
最佳答案
可能不是全部,但我之前遇到过服务器设置的问题。也许你的服务器不支持 =. 的 php echo 简码。所以我建议尝试这个,替换:
<script>
var appurl='<?=$app_url?>',
hosturl='<?=$callback_url?>',
rates=<?=get_x_rates()?>;
</script>
与:
<script>
var appurl='<?php echo $app_url; ?>',
hosturl='<?php echo $callback_url; ?>',
rates=<?php get_x_rates(); ?>;
</script>
在我的本地机器上有所不同。可能有帮助。祝你好运。
关于javascript - 将 JavaScript 变量设置为等于 PHP 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23026991/