2012-05-27 53 views
0

請原諒我的PHP noobness!我想要一個頁面根據傳入鏈接顯示特定的導航。它的設置如下:如何重置GET變量

名單page1.php中項目:

<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'wood-species.php')) echo 'class="current"';?>href="wood-species.php?name=standard">Wood Species</a></li> 

使page2.php列表項:

<li><a <?php if (strpos($_SERVER['PHP_SELF'], 'wood-species.php')) echo 'class="current"';?>href="wood-species.php?name=premium">Wood Species</a></li> 

因此,第一個鏈接設置域名變量設置爲 「標準」 使用GET方法,第二個鏈接將它設置爲「高級」。所以我想要發生的是'wood-species.php'顯示適當的導航,但我不知道如何銷燬或取消設置'name'變量。

這裏就是我試圖使用,顯然沒有得到它做...

<?php 

    $woodclass = $_GET['name']; 
    if($woodclass="premium") { 
    require("includes/premium-wide-navigation.php"); 
    echo"premium"; 
    clearit(); 
    } 

    else if($woodclass="standard") { 
    require("includes/standard-wide-navigation.php"); 
    echo"standard"; 
    clearit(); 
    } 
    else { 
    // 
    } 

    function clearit() { 
    unset($GLOBALS['woodclass']); 
    } 

?> 

回答

4

我認爲,取消設置($ _ GET [ '名']);應該完成這項工作。

+1

這些建議都正在出於某種原因。每次我都會彈出第一個require語句,即使我清除了緩存之後..我一定會遇到另一個問題。 – johnnyb

+0

好的!愚蠢的錯誤,現在正在工作。非常感謝。 – johnnyb

+0

非常歡迎。 –

0

使用JavaScript

形式:

<form method="get" action="<? print $_SERVER['PHP_SELF']; ?>"> <input type="text" name="number" size="5" maxlength="5">
<input type="submit" name="submit" value="Search"> <input id="refresh_custom_input" type="reset"> </form>

的Javascript:

//refresh GET variable 
$('#refresh_custom_input').click(function() { 

    var query = window.location.search.substring(1) 

    if(query.length) { 
     if(window.history != undefined && window.history.pushState != undefined) { 
      window.history.pushState({}, document.title, window.location.pathname); 
     } 
    } 

    window.location.reload(); 
});