$_REQUEST error - very wierd

by lisag
12 replies
$_REQUEST does not contain the variable $lfid unless I echo it first. See below:

Code:
if(is_array($_REQUEST['lfid']))
{
$xfid = $_REQUEST['lfid'];
$lfid=$xfid[0];
echo $lfid.'<br>';
print_r($_REQUEST);


}
else
{
$lfid = $_REQUEST['lfid'] ;
}
if (empty($lfid))
{
print_r($_REQUEST);
die;
}
If I remove the line that echos $lfid, the code goes straight to the if(empty($lfid) line. How's that?
#$request #error #wierd
  • Profile picture of the author phpbbxpert
    You should check to see if $_REQUEST['lfid'] exists and is set first, then check if it is an array or string.

    Does it exist and have a value ?
    {{ DiscussionBoard.errors[3532400].message }}
  • <?php
    var_dump($_REQUEST);
    ?>
    {{ DiscussionBoard.errors[3534231].message }}
    • Profile picture of the author lisag
      Originally Posted by Cash Money Hosting View Post

      <?php
      var_dump(Array);
      ?>
      Here's the deal, strange as it seems.
      This statement is TRUE as long as I have the echo statement. As soon as I remove the echo statement. It drops to the IF EMPTY statement.
      Signature

      -- Lisa G

      {{ DiscussionBoard.errors[3534570].message }}
      • Profile picture of the author SteveJohnson
        Originally Posted by lisag View Post

        Here's the deal, strange as it seems.
        This statement is TRUE as long as I have the echo statement. As soon as I remove the echo statement. It drops to the IF EMPTY statement.
        What you think is happening isn't. No way that it could. The only statement that is evaluated is what's in parentheses.

        Put a unique echo statement in each execution block. That'll help you see what is going on. As it is now, you don't have any way of telling exactly what the original if statement evaluates to.

        Code:
        <?php
            if( is_array( $ _REQUEST['lfid'] ) ) {
                $ xfid = $ _REQUEST['lfid'];
                $ lfid = $ xfid[0];
                echo "i am here";
            }
            else {
                $ lfid = $ _REQUEST['lfid'] ;
                echo "i am there";
            }
            if ( empty( $ lfid ) ) {
                echo "i am nowhere";
            }
        ?>
        Signature

        The 2nd Amendment, 1789 - The Original Homeland Security.

        Gun control means never having to say, "I missed you."

        {{ DiscussionBoard.errors[3535094].message }}
  • Profile picture of the author KirkMcD
    Originally Posted by lisag View Post

    If I remove the line that echos , the code goes straight to the if(empty() line. How's that?
    Are you sure about that?
    Is the print_r($REQUEST) getting displayed twice?
    {{ DiscussionBoard.errors[3535243].message }}
    • Profile picture of the author Tim Brownlaw
      There is something else going on here!

      You are dealing with either an Array or an single value.
      I'm guessing it's an integer going by its name $ lfid

      As Steve mentioned, having the echo there or not won't make any difference.
      You are also using print_r() as well which is also outputting to the screen!
      Does removing the print_r() make any difference????

      What are the test values you are using?
      Are you sending this via a Form using POST?
      What are the values coming from print_r()?

      $_REQUEST let's you either POST or GET data.
      I'm not sure how you would send an array with GET, which is possibly why you are testing for a non array version!

      In regards to the empty() function, it will evaluate to true if it is 0.
      For an ID, that's not a nice number so it will be caught.

      Combining everything mentioned above..
      PHP Code:
      <?php
         
      if(isset($ _REQUEST['lfid'])
         {
          if( 
      is_array( $ _REQUEST['lfid'] ) ) {
              $ 
      xfid = $ _REQUEST['lfid'];
              $ 
      lfid = $ xfid[0];
              echo 
      "i am here";
          }
          else {
              $ 
      lfid = $ _REQUEST['lfid'] ;
              echo 
      "i am there";
          }
          if ( empty( $ 
      lfid ) ) {  // I am probably 0 if I am an integer
              
      echo "i am nowhere";
          }
         }
         else
          echo 
      "Whoops I'm empty";
      ?>
      You should really test for the type - if it's an integer etc...just to be safe.
      I hope that gives you a bit more to play with!

      Cheers
      Tim
      {{ DiscussionBoard.errors[3540300].message }}
  • Profile picture of the author P3 Marketing
    I suggest you use $_GET or $_POST, according to your form method. Using $_REQUEST is generally frowned upon, as it is very bad security practice, and paradoxes like this occur.
    {{ DiscussionBoard.errors[3566284].message }}
  • Profile picture of the author annife polak
    Also it could be a problem a server side. If your problems still remains contact a support of hosting space (server) about this problem. But most likely its problem on your side.

    Cheers.
    {{ DiscussionBoard.errors[6418977].message }}
  • Profile picture of the author eluminousdev
    Hi,

    If
    $_REQUEST['lfid'] is an array then no need to assign it to directly any variable,
    instead you can directly assigns like $variable = $_REQUEST['lfid'][0];
    Rest else is ok. No need to change it.
    {{ DiscussionBoard.errors[6433276].message }}
  • Profile picture of the author SteveJohnson
    I daresay she solved her problem - since the OP IS OVER A YEAR OLD.

    why do you people keep digging up old threads?
    Signature

    The 2nd Amendment, 1789 - The Original Homeland Security.

    Gun control means never having to say, "I missed you."

    {{ DiscussionBoard.errors[6438667].message }}
  • Profile picture of the author seokid
    You should check variable first with isset if variable is set or not
    {{ DiscussionBoard.errors[6438727].message }}
  • Profile picture of the author SteveSRS
    yes me too I would like to UP my post count and pretend I'm adding something to the forum to this super old thread without giving any valuable information what-so-ever [/sarcasm off]
    {{ DiscussionBoard.errors[6517706].message }}

Trending Topics