By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,827 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

isset

P: n/a
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
Feb 10 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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.
Feb 10 '08 #2

P: n/a
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.
js*******@attglobal.net
==================

Feb 10 '08 #3

P: n/a
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($_REQUEST['a'])) ? $_REQUEST['a'] : "";
Feb 10 '08 #4

P: n/a
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($_REQUEST['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
Feb 10 '08 #5

P: n/a
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($_REQUEST['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.
js*******@attglobal.net
==================

Feb 10 '08 #6

P: n/a
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($_REQUEST['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.
js*******@attglobal.net
==================

Feb 11 '08 #7

P: n/a
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
http://tobyinkster.co.uk/blog/2008/0...nce-dumplings/
Feb 11 '08 #8

P: n/a
On Feb 10, 5:06 pm, Simon Dean <sjd...@gmail.comwrote:
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);
Feb 12 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.