PHP&;JavaScript-重定向到动态URL


PHP & JavaScript - Redirecting to a dynamic URL

只是一个简单的问题。

目前,我有一个登录脚本,可以重定向到dashboard.php,用户可以在那里单击一个按钮来检索预先选择的当前月份和年份的谷歌分析统计数据。

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=日期('F');$currentYear=日期('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!"; ?>';