2012-07-31 45 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> 

未經測試...但應該工作。

相關問題