Manipulating Query String
Hi there,
May I know how do I detect whether there is any query string in my url?
For example, my url is http://www.xxxx.com/napp/view.php?vid=1
How do I display an error page when a user types in the wrong url such as:
http://www.xxxx.com/napp/view.php (Without the ?vid=1)
Re: Manipulating Query String
You can acces the whole query string using the following:
PHP Code:
$qs = $_SERVER['QUERY_STRING'];
PHP also loads the variables in the query string into the $_GET super global array. You can check whether it was supplied by using the isset() function:
PHP Code:
if (! isset($_GET['vid'])) {
/* error - no vid set */
}
Re: Manipulating Query String
just do a check on the variable vid
eg.
Code:
if ( !$_GET['vid'] )
{
// redirect to or show error page
}
Re: Manipulating Query String
Quote:
Originally Posted by pelican
just do a check on the variable vid
eg.
Code:
if ( !$_GET['vid'] )
{
// redirect to or show error page
}
That will produce a notice if the variable doesn't exist though.