我想让我的索引页显示当前的季度和年份,以便随着时间的推移而更新。 我需要有关重建代码的帮助。 来了。 它就像某种公告板日历:
$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");
}
将显示的页面已准备就绪,只是我无法显示它并导致以下错误:
警告:include_once(.../index.php?year=2012&quarter=Q3) [function.include-once]:无法打开流:第 121 行的 D:''xampp''htdocs''jet''index.php 中的结果太大
警告:include_once() [function.include]:打开 '.../index.php?year=2012&quarter=Q3' 进行包含 (include_path='.;D:''xampp''php''PEAR') 在 D:''xampp''htdocs''jet''index.php 第 121 行
帮助任何人?
差异。
让我们回到基础,好吗?
您通过URL发送的内容在另一端作为"GET"接收,它需要以超文本形式发送到Web服务器,Web服务器会将信息传递给PHP脚本,PHP脚本将相应地编译它们。所以,这个逻辑是行不通的,因为在包括你玩文件系统。
你想做的是使用 header()
header("location: http://example.com/jet/index.php?year=$get_year&quarter=Q2");
而不是
include_once("../index.php?year=".$get_year."&quarter=Q1");
header() 会将用户重定向为 HTTP 响应。
不要在包含字符串中传递 $_GET 变量。
准备好变量
$year='2012';
$quarter='Q3';
include_once('index.php');
然后运行包含字符串,您可以正常访问年份和季度。确保检查变量的范围。
所以你的完整代码:
$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");
}