问题描述
|
只是一个简单的问题。
目前,我有一个登录脚本,该脚本重定向到dashboard.php,用户可以在其中单击按钮以检索预选当前月份和年份的Google Analytics(分析)统计信息。
2011年5月的网址是:
dashboard.php?month=May&year=2011&submit=Get+Statistics!
因此,我想做的是在页面上加载统计信息,而不必单击按钮。
我能想到的唯一方法是更改登录脚本中的以下行:
// redirect to secure page
document.location=\'dashboard.php\';
像这样:
// redirect to secure page
document.location=\'dashboard.php\' + <?php echo ?month=currentMonth&year=currentYear&submit=Get+Statistics! ?>\';
月份和年份变量设置如下:
$ currentMonth = date(\'F \');
$ currentYear = date(\'Y \');
但这是行不通的,它照常进入了dashboard.php。
有任何想法吗?
解决方法
您缺少第二个字符串前面的单引号:
document.location=\'dashboard.php\' + \'<?php echo \"?month=currentMonth&year=currentYear&submit=Get+Statistics!\" ?>\';
应该可以在PHP文件中使用。
, 我不知道这是否是您撰写帖子的时间,但是您的回声缺少引号:
尝试这个 :
document.location=\'dashboard.php\' + <?php echo \"?month=currentMonth&year=currentYear&submit=Get+Statistics!\"; ?>\';
, 只要您处于同一范围内,就可以在代码的任何部分中获取变量:
// redirect to secure page
document.location=\'dashboard.php\' + <?= \"?month=$currentMonth&year=$currentYear&submit=Get+Statistics!\"; ?>\';