473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Feb 10 '08 #1
8 2363
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: christian9997 | last post by:
Hi I don't seem to understand the way isset works. Here is some Javascript code that makes a call using PHP: // USER CAME BACK TO CHANGE LANGUAGE if (<?echo isset($_REQUEST)?>) {...
2
by: Pedro Fonseca | last post by:
Greetings everyone! I'm porting everything to PHP5. I have session variables in all of my web application. Until PHP5 I was using session variables like: if ($_SESSION == 'Bar') { $value = 5;...
9
by: wouter | last post by:
hey hi..... I wanna make a switch wich does this: if pagid is set do A, if catid is set do B, if projectid is set do C, else do D. So i was thinking something like this:
2
by: sathyashrayan | last post by:
Dear group, My question may be novice. I have seen codes where the isset() is used to test weather a user's session ($_SESSION) is set before entering a page. A kind of direct access to a page is...
2
by: yawnmoth | last post by:
<?php $var = 'test'; echo isset($var) ? 'true' : 'false'; echo '<br>'; echo isset($var) ? 'true' : 'false'; ?> Why does that result in this output?:
8
by: Giovanni R. | last post by:
Take a look at this code (you can execute it): error_reporting(E_ALL); function byVal( $v) {} function byRef(&$v) {} print '<pre>'; byVal ($first); // gives a notice
9
by: arundelo | last post by:
Is there a way to tell whether accessing a variable will result in an "Undefined variable" E_NOTICE? isset() almost does this, but it also returns false if a variable is set to null: ...
10
by: major | last post by:
The following code processes a blank field as though it has some value and proceeds as though it was set to some value. Apparently isset() is not working, because it thinks that a blank text...
0
by: Michael Fesser | last post by:
..oO(Daniel Molina Wegener) They have side effects or don't work properly. If the variable or element you want to check doesn't exist, then * the first and fourth will create it and set it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.