当没有$ _REQUEST时,“if else声明”

I am making a simple if and else statement to get value from a requested link my code is

if($_REQUEST['f_id']=='')
{
    $friend_id=0;
}
else
{
    $friend_id=$_REQUEST['f_id'];
}

and suppose the link is www.example.com/profile.php?f_id=3

now its simple as if the f_id is empty or with value either of the above if and else statement would run. but what is a user is just playing around with link and he removes the whole ?f_id=3 with link left to be opened with www.example.com/profile.php then how to detect that f_id dosen't exist and in that case redirect to a error page ?

you can use the isset() php function to test that:

if(!isset($_REQUEST) || $_REQUEST['f_id']=='')
{ 
   $friend_id=0; 
} 
else 
{ 
  $friend_id=$_REQUEST['f_id']; 
} 
if ( isset( $_REQUEST['f_id'] ) ) {
    if($_REQUEST['f_id']=='') {
        $friend_id=0;
    } else {
        $friend_id=$_REQUEST['f_id'];
    }
} else {
    REDIRECT TO ERROR PAGE
}

UPDATE Since your URLS-s look like www.example.com/profile.php?f_id=3 you should use $_GET instead of $_REQUEST

You could use empty to combine the 2x isset into 1 statement (unless you actually have a friend_id of 0 which would result in empty being true)

if(empty($_REQUEST['f_id'])) {
   $friend_id=0;
} else {
  $friend_id=$_REQUEST['f_id'];
}

Late answer, but here's an "elegant" solution that I always use. I start with this code for all the variables I'm interested in and go from there. There are a number of other things you can do with the extracted variables as well shown in the PHP EXTRACT documentation.

// Set the variables that I'm allowing in the script (and optionally their defaults)
    $f_id = null        // Default if not supplied, will be null if not in querystring
    //$f_id = 0         // Default if not supplied, will be false if not in querystring
    //$f_id = 'NotFound'    // Default if not supplied, will be 'NotFound' if not in querystring

// Choose where the variable is coming from
    extract($_REQUEST, EXTR_IF_EXISTS); // Data from GET or POST
    //extract($_GET, EXTR_IF_EXISTS);   // Data must be in GET
    //extract($_POST, EXTR_IF_EXISTS);  // Data must be in POST

if(!$f_id) {
    die("f_id not supplied...do redirect here");
}