2012-07-31 48 views
0

我的链接样本看起来像这样“/jet/index.php?year=2011 & quarter = Q1” 现在我需要显示包含第一个月的页面季度之一2011年。 /jet/index.php?year=2011 &季度= Q1将显示四月五月六月。等等。通过url中的多个变量显示一个页面

我的代码看起来像这样

<a href="index.php?year=2011&quarter=Q1"> 
    <a href="index.php?year=2011&quarter=Q2"> 
    <a href="index.php?year=2011&quarter=Q1"> 
    <a href="index.php?year=2011&quarter=Q4"> 

我的主页,这是2012年的作品就好了,这里是代码

<?php 
$quarters = array('Q1' => 'firstq2012.php', 'Q2' => 'secondq2012.php', 'Q3' => 'thirdq2012.php', 'Q4' => 'fourthq2012.php'); 
if(isset($_GET['quarter'])) { 
    if(in_array($_GET['quarter'], array_keys($quarters))) { 
     include_once $quarters[$_GET['quarter']]; 
    } else { 
     header('Location: 404.php'); 
    } 
} else { 
    include_once $quarters['Q3']; 
} 
?> 

我需要你的帮助,我会从过渡2012年至2011年会看起来像(我通过链接)

谢谢!

+0

很难解释你的问题 – asprin 2012-07-31 11:05:49

+0

在你上线之前:http://www.aeonity.com/frost/how-preventing-remote-file-inclusion-exploits-php – madflow 2012-07-31 11:16:24

回答

0

我会改变你的代码完全...

代码检查,包括宿舍

<?php 
if(isset($_GET['year']) && isset($_GET['quarter'])) { 
// get params 
$year = (strlen($_GET['year']) == 4 && is_numeric($_GET['year']) ? (int)$_GET['year'] : date('Y')); 
$quarter = (substr($_GET['quarter'], 0, 1) == 'Q' && is_numeric(substr($_GET['quarter'], 1, 1)) ? (int)substr($_GET['quarter'], 1, 1) : ceil(date('n')/4)); 

$quartalsNumberToName = array(
    1 => 'first', 
    2 => 'second', 
    3 => 'third', 
    4 => 'fourth' 
); 
$filename = $quartalsNumberToName[$quarter] .'q'. $year .'.php'; 

if(file_exists($filename)) { 
    include_once($filename); 
} else { 
    header('Location: 404.php'); 
    exit; 
} 
} else { 
include_once($quartalsNumberToNume[3] .'q2012.php'; 
} 
?> 

代码生成链接:

<ul> 
<?php 
// the start year 
$yearStart = 2011; 

for($i = $yearStart; $i <= date('Y'); $i++) { 
    for($j = 1; $j <= 4; $j++) { 
?> 
    <li><a href="index.php?year=<?php echo($i); ?>&amp;quarter=Q<?php echo($j); ?>">Year <?php echo($i); ?>, Quarter <?php echo($j); ?></a></li> 
<?php 
    } 
} 
?> 
</ul> 

未经测试...但应该工作。

相关问题