2012-11-07 140 views
0

推送斜線我有一個窗體,當你點擊搜索時,它會用%2F而不是斜線寫出網址。我怎樣才能解決這個問題?用斜槓向網址

代碼:

<form name="cdsearch" method="get" action=""> 
<input type="hidden" name="route" value="database/comics" /> <-- This is where the slash is needed 
<input style="width: 100%;" type="text" name="q" value="<?php echo $q ?>" /><br/> 
<input style="width: 100%;" type="submit" value="Search Comic Database" />  
</form> 
+0

這就是所謂的URL編碼。使用url_decode – Chris

+0

我會在哪裏使用這個? – rackemup420

回答

1

嘗試

<form name="cdsearch" method="POST" action="redir.php"> 
    <input type="hidden" name="route" value="database/comics" /> <-- This is where the slash is needed 
    <input style="width: 100%;" type="text" name="q" value="<?php echo $q ?>" /><br/> 
    <input style="width: 100%;" type="submit" value="Search Comic Database" />  
</form> 

redir.php

<?php 

if($_POST){ //check that the form has been posted 
    $route = url_decode($_POST['route']); 
    $query = $_POST['query']; 
    //echo $_POST['route']." has been changed to ".$route; // <--- for testing 
    header("Location: ".$route."/?query=".$query); // redirect the user now the url has been decoded 
    exit(); 
} 

?>