URLを呼び出した後、ファイルex.phpにリダイレクトしたいと思いますが、今回はパラメーターなしです。そのためには、ex.phpで次のコードを使用してみてください
<?
if($_GET['name']!='' || $_GET['price']!='' ||$_GET['quantity']!='' ||$_GET['code']!='' || $_GET['search']!=''){
/* here the code checks whether the url contains any parameters or not, if yes it will execute parameters stuffs and it will get redirected to the page http://localhost/join/prog/ex.php without any parameters*/
/* do what ever you wish to do, when the parameters are present. */
echo $name;
print $price;
//etc....
$location="http://localhost/join/prog/ex.php";
echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
exit;
}
else{
/* here rest of the body i.e the codes to be executed after redirecting or without parameters.*/
echo "Hi no parameters present!";
}
?>
ここで、uが行ったことは、クエリ文字列にパラメータが含まれているかどうかを確認せずに、リダイレクトを同じページにリダイレクトするだけです。コードはパラメータの存在をインテリジェントにチェックします。パラメータがあれば、ex.phpにリダイレクトされます。それ以外の場合は、「Hi no parameterspresent!」と出力されます。ストリング!