php判斷URL參數中是否存在某些項

<?php
$old_url = $_SERVER["REQUEST_URI"];
//檢查連接中是否存在 ?
$check = strpos($old_url, '?');
//若是存在 ?
if($check !== false)
{
//若是 ? 後面沒有參數,如 http://www.yitu.org/index.php?
if(substr($old_url, $check+1) == '')
{
//能夠直接加上附加參數
$new_url = $old_url;
}
else //若是有參數,如:http://www.yitu.org/index.php?ID=12
{
$new_url = $old_url.'&';
}
}
else //若是不存在 ?
{
$new_url = $old_url.'?';
}
echo $new_url;
?> 
相關文章
相關標籤/搜索