繁体   English   中英

PHP & JavaScript - 重定向到动态 URL

[英]PHP & JavaScript - Redirecting to a dynamic URL

只是一个快速的问题。

目前我有一个登录脚本,它重定向到dashboard.php,用户可以点击一个按钮来检索预选的当前月份和年份的谷歌分析统计信息。

2011 年 5 月的 url 是: 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!"; ?>';

只要你在同一个scope,就可以得到代码任意部分的变量:

// redirect to secure page
document.location='dashboard.php' + <?= "?month=$currentMonth&year=$currentYear&submit=Get+Statistics!"; ?>';

暂无
暂无

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

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