isset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Dean

    isset

    Im taking Im doing something stupid here? I thought it was clever...
    just learned a little more about isset.

    $a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
    $_POST['a'] : "";

    I guess you can see what try each successive one in turn as we can
    alternate between the two.

    But it doesn't seem to be working.

    For example, if I construct a URL for:

    somepage.php?a= something

    In the script, $a is not something, $a = "".

    But if I post on a form, then $a="something" .

    If I switch the syntax round to POST first then GET, then I get a reversal.

    It's like the first isset is being ignored.

    I take it I can't have nested issets in this fashion?

    Cheers
    Simon
  • The Natural Philosopher

    #2
    Re: isset

    Simon Dean wrote:
    Im taking Im doing something stupid here? I thought it was clever...
    just learned a little more about isset.
    >
    $a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
    $_POST['a'] : "";
    >
    I guess you can see what try each successive one in turn as we can
    alternate between the two.
    >
    But it doesn't seem to be working.
    >
    For example, if I construct a URL for:
    >
    somepage.php?a= something
    >
    In the script, $a is not something, $a = "".
    >
    But if I post on a form, then $a="something" .
    >
    If I switch the syntax round to POST first then GET, then I get a reversal.
    >
    It's like the first isset is being ignored.
    >
    I take it I can't have nested issets in this fashion?
    >
    Cheers
    Simon
    No sure but try more brackets.

    Comment

    • Jerry Stuckle

      #3
      Re: isset

      Simon Dean wrote:
      Im taking Im doing something stupid here? I thought it was clever...
      just learned a little more about isset.
      >
      $a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
      $_POST['a'] : "";
      >
      I guess you can see what try each successive one in turn as we can
      alternate between the two.
      >
      But it doesn't seem to be working.
      >
      For example, if I construct a URL for:
      >
      somepage.php?a= something
      >
      In the script, $a is not something, $a = "".
      >
      But if I post on a form, then $a="something" .
      >
      If I switch the syntax round to POST first then GET, then I get a reversal.
      >
      It's like the first isset is being ignored.
      >
      I take it I can't have nested issets in this fashion?
      >
      Cheers
      Simon
      >
      It works fine if you watch your operator precedence:

      $a = isset($_GET['a']) ? $_GET['a'] :
      (isset($_POST['a']) ? $_POST['a'] : "");


      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Tony

        #4
        Re: isset

        Simon Dean wrote:
        Im taking Im doing something stupid here? I thought it was clever...
        just learned a little more about isset.
        >
        $a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
        $_POST['a'] : "";
        >
        Others have helped with the specific problem - I'm just wondering: Is
        there a reason you can't use $_REQUEST? Is there any case where
        $_GET['a'] AND $_POST['a'] would both be set?

        $a = (isset($_REQUES T['a'])) ? $_REQUEST['a'] : "";

        Comment

        • Simon Dean

          #5
          Re: isset

          Tony wrote:
          Simon Dean wrote:
          >Im taking Im doing something stupid here? I thought it was clever...
          >just learned a little more about isset.
          >>
          >$a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
          >$_POST['a'] : "";
          >>
          >
          Others have helped with the specific problem - I'm just wondering: Is
          there a reason you can't use $_REQUEST? Is there any case where
          $_GET['a'] AND $_POST['a'] would both be set?
          >
          $a = (isset($_REQUES T['a'])) ? $_REQUEST['a'] : "";
          Hrm.

          Probably not, and that looks an awful lot tidier. Thank you again.

          When I keep seeing such simple things as this I keep wondering if I
          should give up programming as it seems Im certainly not keeping myself
          up to date at all!

          Request!

          Cheers
          Simon

          Comment

          • Jerry Stuckle

            #6
            Re: isset

            Tony wrote:
            Simon Dean wrote:
            >Im taking Im doing something stupid here? I thought it was clever...
            >just learned a little more about isset.
            >>
            >$a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
            >$_POST['a'] : "";
            >>
            >
            Others have helped with the specific problem - I'm just wondering: Is
            there a reason you can't use $_REQUEST? Is there any case where
            $_GET['a'] AND $_POST['a'] would both be set?
            >
            $a = (isset($_REQUES T['a'])) ? $_REQUEST['a'] : "";
            >
            Not good - $_REQUEST can also get the data from other places - like
            $_COOKIE, for instance.

            $_REQUEST should be used seldom, if at all. It's too easy to abuse.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Jerry Stuckle

              #7
              Re: isset

              Simon Dean wrote:
              Tony wrote:
              >Simon Dean wrote:
              >>Im taking Im doing something stupid here? I thought it was clever...
              >>just learned a little more about isset.
              >>>
              >>$a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
              >>$_POST['a'] : "";
              >>>
              >>
              >Others have helped with the specific problem - I'm just wondering: Is
              >there a reason you can't use $_REQUEST? Is there any case where
              >$_GET['a'] AND $_POST['a'] would both be set?
              >>
              >$a = (isset($_REQUES T['a'])) ? $_REQUEST['a'] : "";
              >
              Hrm.
              >
              Probably not, and that looks an awful lot tidier. Thank you again.
              >
              When I keep seeing such simple things as this I keep wondering if I
              should give up programming as it seems Im certainly not keeping myself
              up to date at all!
              >
              Request!
              >
              Cheers
              Simon
              >
              Simon,

              See my response to Tony. You don't want to use $_REQUEST - it can be a
              security exposure.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              • Toby A Inkster

                #8
                Re: isset

                Jerry Stuckle wrote:
                See my response to Tony. You don't want to use $_REQUEST - it can be a
                security exposure.
                It's not as big a security problem as people like to make out.

                $_REQUEST is basically a union of $_GET, $_POST and $_COOKIE. The
                "security problem" myth comes from the idea of:

                you might be trying to read some POST data or a
                cookie, but the user could add "?foo=bar" to the URL
                to trick you into reading their forged data.

                But cookies and POST data are barely any more difficult to forge
                than GET data is. Using $_POST['foo'] instead of $_GET['foo'] so
                that people can't hack your app by adding a query string will give
                you a false sense of security.

                --
                Toby A Inkster BSc (Hons) ARCS
                [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
                [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 12 days, 19:08.]

                Mince & Dumplings

                Comment

                • Betikci Boris

                  #9
                  Re: isset

                  On Feb 10, 5:06 pm, Simon Dean <sjd...@gmail.c omwrote:
                  Im taking Im doing something stupid here? I thought it was clever...
                  just learned a little more about isset.
                  >
                  $a = (isset($_GET['a'])) ? $_GET['a'] : (isset($_POST['a'])) ?
                  $_POST['a'] : "";
                  >
                  I guess you can see what try each successive one in turn as we can
                  alternate between the two.
                  >
                  But it doesn't seem to be working.
                  >
                  For example, if I construct a URL for:
                  >
                  somepage.php?a= something
                  >
                  In the script, $a is not something, $a = "".
                  >
                  But if I post on a form, then $a="something" .
                  >
                  If I switch the syntax round to POST first then GET, then I get a reversal.
                  >
                  It's like the first isset is being ignored.
                  >
                  I take it I can't have nested issets in this fashion?
                  >
                  Cheers
                  Simon
                  I use if - else or switch control operator instead of "? and :" but
                  the usage is like that (condition ? true : false);

                  Comment

                  Working...