将JavaScript变量设置为等于PHP变量
我在GitHub上下载了某人的项目,该项目使Facebook用户能够相互发送比特币。他一年前放弃了开发,我想构建自己的应用程序,但我目前正在查看他的代码,并试图建立我的开发环境 我有点理解PHP,它的意思是用于服务器端脚本,JavaScript是在客户端机器上执行的(都在浏览器中,Node.js是服务器端框架) 不管怎么说,他在做一件奇怪的事,这会产生一个错误 目录结构如下:将JavaScript变量设置为等于PHP变量,javascript,php,facebook,bitcoin,Javascript,Php,Facebook,Bitcoin,我在GitHub上下载了某人的项目,该项目使Facebook用户能够相互发送比特币。他一年前放弃了开发,我想构建自己的应用程序,但我目前正在查看他的代码,并试图建立我的开发环境 我有点理解PHP,它的意思是用于服务器端脚本,JavaScript是在客户端机器上执行的(都在浏览器中,Node.js是服务器端框架) 不管怎么说,他在做一件奇怪的事,这会产生一个错误 目录结构如下: inc/ init.php app.php btc.php index.php settings.php
inc/
init.php
app.php
btc.php
index.php
settings.php
有更多的文件,但我认为以上内容就足够了。因此,我运行命令“php-slocalhost:8000”,它启动一个服务器 我转到localhost,页面呈现后,我在终端中得到以下错误:
[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>
比特币交易
var appurl=“”,
hosturl=“”,
比率=;
....
既然他在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短代码;
与:
var appurl=“”,
hosturl=“”,
比率=;
在我的本地机器上做出了改变。也许会有帮助。祝你好运。可能不是全部,但我以前遇到过服务器设置问题。可能您的服务器不支持的php echo短代码; 与:
var appurl=“”,
hosturl=“”,
比率=;
在我的本地机器上做出了改变。也许会有帮助。祝你好运。我认为这些文件没有包括在内。请尝试这样做:
require dirname(__FILE__) . '/settings.php';
require dirname(__FILE__) . '/inc/btc.php';
require dirname(__FILE__) . '/inc/app.php';
require dirname(__FILE__) . '/inc/init.php';
我认为这些文件没有包括在内。请尝试这样做:
require dirname(__FILE__) . '/settings.php';
require dirname(__FILE__) . '/inc/btc.php';
require dirname(__FILE__) . '/inc/app.php';
require dirname(__FILE__) . '/inc/init.php';
可能您的php.ini设置没有活动的短标记,请检查您的php.ini设置(短标记)
或者您可以尝试替换
可能您的php.ini设置没有激活的短标记,请检查您的php.ini设置(短标记)
或者您可以尝试替换尝试将变量声明为全局变量,方法是在其声明之前添加global关键字。尝试将变量声明为全局变量,通过在声明之前添加全局关键字。尝试替换尝试替换我的建议是使用体面的PHP IDE来减少神秘的猜测,在错误日志中显示的行设置断点,并使用中断异常功能,以便IDE在检测到问题时停止。体面的IDE通常还内置了代码验证器,因此即使不运行代码,IDE也可以向您显示错误(很可能是在处理不稳定的废弃代码时)
- 据我所知,具有非常成熟的调试器和中断异常功能的PHP IDE是-#1个PHP调试器
- PHP IDE具有非常成熟的代码分析器(他们称之为“检查”),显示了许多潜在问题,而无需运行代码。据我所知,这是-1个PHP代码分析器
我的建议是通过使用一个体面的PHP IDE来减少神秘的猜测,在错误日志中显示的行上设置断点,并使用异常中断功能,以便IDE在检测到问题时停止。体面的IDE通常还内置了代码验证器,因此即使不运行代码,IDE也可以向您显示错误(很可能是在处理不稳定的废弃代码时)
- 据我所知,具有非常成熟的调试器和中断异常功能的PHP IDE是-#1个PHP调试器
- PHP IDE具有非常成熟的代码分析器(他们称之为“检查”),显示了许多潜在问题,而无需运行代码。据我所知,这是-1个PHP代码分析器
使用PHP设置JavaScript变量很有帮助,但并不总是这样。例如,PHP不能临时修改外部.js文档。它永远改变了他们
您可以使用下面的代码
<script type="text/javascript">
var php = <?php echo $phpVar ?>;
</script>
var php=;
使用PHP设置JavaScript变量很有帮助,但并不总是这样。例如,PHP不能临时修改外部.js文档。它永远改变了他们
您可以使用下面的代码
<script type="text/javascript">
var php = <?php echo $phpVar ?>;
</script>
var php=;
我看到您在index.php上使用的函数(get_x_rates)没有定义,请将此函数添加到注释中或检查此函数在任何文件中的定义位置?我看到您在index.php上使用的函数(get_x_rates)没有定义,将此函数添加到注释或检查此函数在任何文件中的定义位置?以下是我认为正在发生的情况
php.ini
中的short_open_标记确实已关闭。
文件index.php
使用了标签,我认为这就是正在发生的事情
php.ini
中的short_open_标记确实已关闭。
文件index.php
使用了标签,这让我很恼火,所以
有几个问题:
这些文件没有结束php标记+最好是拼写出来
你建立数据库了吗?通过添加$rates=“hello”,在btc.php中测试该函数;返回美元汇率;在函数的顶部,就在打开函数()的下面{
我已经完成了这两项工作,只是我没有设置数据库来检查功能。这让我很恼火,所以
有几个问题:
这些文件没有结束php标记+最好是拼写出来
你安排好了吗
var url = //your url
echo "url = //your new url"