views:

141

answers:

3

How can you make the if -clause which do this and this if

  1. there is no variable in the URL by PHP?
  2. there is no variable which has value in the URL by PHP?

Examples of the URLs which should be true for the if -clause for #1:

www.example.com/index.php
example.com/index.php
example.com/index.php?

Examples of the URLs which should be true for the if -clause for #2:

example.com/index.php?successful_registration
example.com/index.php?successful_login

The following is my unsuccessful if -clause for $1

if (isset($_REQUEST[''])) {
      // do this
}
+2  A: 

You'd want to check $_GET and $_SERVER["query_string"].

If the query string is empty, you've got just the base url. If the query string is not empty, but one of the $_GET variables is empty, you've got an invalid domain.

Jonathan Sampson
+7  A: 
if ( 0 == count( $_GET ) )
{
  // do this
}

or

if ( empty( array_keys( $_GET ) ) )
{
  // do this
}

or

if ( '' == $_SERVER['QUERY_STRING'] )
{
  // do this
}
Peter Bailey
or a simpler version: if (empty($_GET)) { ...
Lepidosteus
A: 

If statements are not loops. You might call it an condition though.

if(isset($_REQUEST['successful_registration'])) {
  //do this
}elseif(isset($_REQUEST['successful_login'])) {
  //do this
}else{
  //do this
}
camomileCase