473,569 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2374
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*******@attgl obal.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($_REQUES T['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($_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
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($_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.
js*******@attgl obal.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($_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.
js*******@attgl obal.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.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);
Feb 12 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3422
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)?>) { alert("WORKS1"); desiredLanguage = "<?echo $_REQUEST?>";
2
6852
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; } $_SESSION is of course set on some other script. But this now
9
9692
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
37140
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 not possible. But I tested with the "input type="button" and the clicking of the event is not happened. Can any one tell me why. The code: <html>...
2
2571
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
2446
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
4483
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: $SetNonNull = 0; $SetNull = null; var_dump(isset($SetNonNull)); // bool(true) $Junk = $SetNonNull; // No error, as predicted by isset()....
10
2359
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 field is set to something. Please let me know how to use isset() correctly. Thanks ahead.
0
226
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 to NULL * the second and third will throw an E_NOTICE error Micha
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.