如何在php中包含URL?
我想让我的索引页面显示当前的季度和年度,这样它就会随着时间的推移而更新。我需要重建代码的帮助。给你。它就像某种形式的公告牌日历:如何在php中包含URL?,php,url,dynamic,include,Php,Url,Dynamic,Include,我想让我的索引页面显示当前的季度和年度,这样它就会随着时间的推移而更新。我需要重建代码的帮助。给你。它就像某种形式的公告牌日历: $now = new DateTime(); $month = (int)$now->format("m"); $get_year = date("Y"); if ($month >= 1 AND $month <= 3) { include_once("../index.php?year=
$now = new DateTime();
$month = (int)$now->format("m");
$get_year = date("Y");
if ($month >= 1 AND $month <= 3) {
include_once("../index.php?year=".$get_year."&quarter=Q1");
}
elseif ($month >= 4 AND $month <= 6) {
include_once("../jet/index.php?year=".$get_year."&quarter=Q2");
}
elseif ($month >= 7 AND $month <= 9) {
include_once("../jet/index.php?year=".$get_year."&quarter=Q3");
}
else {
include_once("../jet/index.php?year=".$get_year."&quarter=Q4");
}
$now=new DateTime();
$month=(int)$now->format(“m”);
$get_year=日期(“Y”);
如果($month>=1,$month=4,$month=7,$month差异
让我们回到基础上来,好吗
通过URL发送的内容在另一端作为“GET”接收,它需要作为超文本发送到Web服务器,Web服务器将信息传递给PHP脚本,PHP脚本将相应地编译它们。因此,这种逻辑将不起作用,因为在include中,您将使用文件系统
您要做的是使用header()
而不是
include_once("../index.php?year=".$get_year."&quarter=Q1");
将以HTTP响应的形式重定向用户。不要在包含字符串中传递$\u GET变量
准备好变量
$year='2012';
$quarter='Q3';
include_once('index.php');
然后运行include字符串,您可以正常访问年度和季度。确保检查变量的范围
因此,您的完整代码:
$year=$get_year;
if ($month >= 1 AND $month <= 3) {
$quarter='Q1';
include_once("../index.php");
}
elseif ($month >= 4 AND $month <= 6) {
$quarter='Q2';
include_once("../jet/index.php");
}
elseif ($month >= 7 AND $month <= 9) {
$quarter='Q3';
include_once("../jet/index.php");
}
else {
$quarter='Q4';
include_once("../jet/index.php");
}
$year=$get\u year;
如果($month>=1,$month=4,$month=7,$month=7,$month可能重复,请浏览这篇文章1.你在index.php的第121行有什么?@IonutFlaviusPogacian include_once(../jet/index.php?year=“.get_year.”和quarter=Q3”);@IonutFlaviusPogacian他想要的已经被我和header()不会放入无限循环。我不认为这是他想要的;他在index.php中,他怎么能再次包含index.php?这将是一个无限循环。他没有提到哪个脚本包含哪个脚本。但他已经包含index.php,这从错误中可以明显看出。警告:include_once(…/index.php?year=2012&quarter=Q3)我想在日期每年和每月发生变化时动态更改索引页。你的答案似乎是这样的:索引将是静态的,因为变量是定义的,而不是基于日期函数。你可以在每个If语句中再次指定变量。检查更新的代码。谢谢!这很有效。我刚刚意识到我有多容易忘记header函数。再次感谢!这将不包括脚本,这将把服务器重定向到另一个脚本。@MinaYoussef,这就是Jet一直试图做的:)这实现了Jet想要的,但Jet试图包含脚本。header和include之间的区别很明显。
$year=$get_year;
if ($month >= 1 AND $month <= 3) {
$quarter='Q1';
include_once("../index.php");
}
elseif ($month >= 4 AND $month <= 6) {
$quarter='Q2';
include_once("../jet/index.php");
}
elseif ($month >= 7 AND $month <= 9) {
$quarter='Q3';
include_once("../jet/index.php");
}
else {
$quarter='Q4';
include_once("../jet/index.php");
}