FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Parameter passing question
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Parameter passing question [message #173537] Mon, 18 April 2011 17:03 Go to next message
Chuck Lavin is currently offline  Chuck Lavin
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
Hi --

I'm having a problem understanding what would be the proper function to use
here ...

How do I tell these three passed parameters apart (PHP 5)?

http://www.somewhere.com?param=value // param has been set to 'value'

http://www.somewhere.com?param= // param has been set to empty (or null)

http://www.somewhere.com // param has not been set at all


I can pull the parameter and check whether or not it's empty, but I also
need to know that it hasn't been referenced at all.

TIA
CL
Re: Parameter passing question [message #173540 is a reply to message #173537] Mon, 18 April 2011 17:42 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Mon, 18 Apr 2011 13:03:24 -0400, Chuck Lavin wrote:

> How do I tell these three passed parameters apart (PHP 5)?

> http://www.somewhere.com?param=value // param has been set to 'value'
> http://www.somewhere.com?param= // param has been set to empty (or
> null)
> http://www.somewhere.com // param has not been set at all

This smells like it might be a homework question, or someone doing a
w3schools online certification, but I'll bite.

Have you tried something like the following:

<?php
if (isset($_GET['x'])) {
if ($_GET['x'] == null) {
// it's null
} else {
// it has data
}
} else {
// it's not defined
}
?>

If you have tried it, did it do what you want, and if not how did it fail
to do so[1]?

If you haven't tried it, what have you tried so far?

If you can't figure out what to use for x, please ask your teacher to
revise passing parameters with you again.

Rgds

Denis McMahon

[1] I don't think it quite does what you want, but I also think the
change that needs to be made is trivial and you should be able to deduce
it yourself.
Re: Parameter passing question [message #173541 is a reply to message #173540] Mon, 18 April 2011 18:14 Go to previous messageGo to next message
Unrest is currently offline  Unrest
Messages: 10
Registered: April 2011
Karma: 0
Junior Member
Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
> <?php
> if (isset($_GET['x'])) {
> if ($_GET['x'] == null) {
> // it's null
> } else {
> // it has data
> }
> } else {
> // it's not defined
> }
> ?>
>

isset() checks if a variable exists and _is not null_.
-> http://de.php.net/manual/en/function.isset.php

so your "if ($_GET['x'] == null)" will never evaluate to true.


Yours,
Michael
Re: Parameter passing question [message #173542 is a reply to message #173540] Mon, 18 April 2011 18:20 Go to previous messageGo to next message
Chuck Lavin is currently offline  Chuck Lavin
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
This is not a homework assignment. I'm working on a live remote server that
I'd rather not be playing around with.

According to the PHP doc page for isset(), isset() can't tell the difference
between a variable that's not set and a variable that's empty.

I need to move passed parameters into session variables:

1) If a parameter is passed with a value, set the session variable with that
value;

2) If a parameter is passed with an empty value, get rid of that session
variable;

3) If a parameter is not passed at all (not referenced in the URL), don't
touch the session variable.

And right now I can't tell the difference between a parameter being passed
empty and no parameter being passed at all.

Tnx
CL

"Denis McMahon" <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote in message
news:4dac7807$0$23634$bed64819(at)gradwell(dot)net...
> On Mon, 18 Apr 2011 13:03:24 -0400, Chuck Lavin wrote:
>
>> How do I tell these three passed parameters apart (PHP 5)?
>
>> http://www.somewhere.com?param=value // param has been set to 'value'
>> http://www.somewhere.com?param= // param has been set to empty (or
>> null)
>> http://www.somewhere.com // param has not been set at all
>
> This smells like it might be a homework question, or someone doing a
> w3schools online certification, but I'll bite.
>
> Have you tried something like the following:
>
> <?php
> if (isset($_GET['x'])) {
> if ($_GET['x'] == null) {
> // it's null
> } else {
> // it has data
> }
> } else {
> // it's not defined
> }
> ?>
>
> If you have tried it, did it do what you want, and if not how did it fail
> to do so[1]?
>
> If you haven't tried it, what have you tried so far?
>
> If you can't figure out what to use for x, please ask your teacher to
> revise passing parameters with you again.
>
> Rgds
>
> Denis McMahon
>
> [1] I don't think it quite does what you want, but I also think the
> change that needs to be made is trivial and you should be able to deduce
> it yourself.
>
Re: Parameter passing question [message #173543 is a reply to message #173541] Mon, 18 April 2011 18:23 Go to previous messageGo to next message
Chuck Lavin is currently offline  Chuck Lavin
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
My point exactly. How can I tell if a URL does not reference a parameter at
all?

I need to move passed parameters into session variables:

1) If a parameter is passed with a value, set the session variable with that
value;

2) If a parameter is passed with an empty value, get rid of that session
variable;

3) If a parameter is not passed at all (not referenced in the URL), don't
touch the session variable.

Tnx
CL

"Unrest" <unrest(at)nullvector(dot)org> wrote in message
news:4dac7f92$0$68307$afc38c87(at)news5(dot)united-newsserver(dot)de...
> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>> <?php
>> if (isset($_GET['x'])) {
>> if ($_GET['x'] == null) {
>> // it's null
>> } else {
>> // it has data
>> }
>> } else {
>> // it's not defined
>> }
>> ?>
>>
>
> isset() checks if a variable exists and _is not null_.
> -> http://de.php.net/manual/en/function.isset.php
>
> so your "if ($_GET['x'] == null)" will never evaluate to true.
>
>
> Yours,
> Michael
>
Re: Parameter passing question [message #173545 is a reply to message #173541] Mon, 18 April 2011 18:28 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Unrest wrote:

> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>> <?php
>> if (isset($_GET['x'])) {
>> if ($_GET['x'] == null) {
>> // it's null
>> } else {
>> // it has data
>> }
>> } else {
>> // it's not defined
>> }
>> ?>
>>
>
> isset() checks if a variable exists and _is not null_.
> -> http://de.php.net/manual/en/function.isset.php
>
> so your "if ($_GET['x'] == null)" will never evaluate to true.

True.

if (array_key_exists('x', $_GET))
{
if ($_GET['x'] == null)
{
// ...
}
}

would make sense then.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$8300dec7(at)news(dot)demon(dot)co(dot)uk>
Re: Parameter passing question [message #173547 is a reply to message #173543] Mon, 18 April 2011 18:34 Go to previous messageGo to next message
Chuck Lavin is currently offline  Chuck Lavin
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
I have this IF statement:

if (isset($_SESSION['COMPANY_CODE'])) {
$COMPANY_CODE = $_SESSION['COMPANY_CODE'];
} else {
$query = parse_str($_SERVER['QUERY_STRING']);
$COMPANY_CODE = $app;
$_SESSION['COMPANY_CODE'] = $COMPANY_CODE;
}

It currently does the reverse of what I need it to do. This block gives
precedence to the session variable. If the session variable exists, the
passed parameter is ignored.

I need to give precedence to the passed parameter. If the parameter is
passed (either with a value or empty), I need to modify the session variable
accordingly. If the parameter is not passed, I want to leave the session
variable untouched.

As I understand it, checking for isset($app) will not tell the difference
between http://www.somewhere.com/?app= and http://www.somewhere.com .


"Chuck Lavin" <x(at)x(dot)x> wrote in message
news:Qk%qp(dot)16994$7N3(dot)5715(at)newsfe10(dot)iad...
> My point exactly. How can I tell if a URL does not reference a parameter
> at all?
>
> I need to move passed parameters into session variables:
>
> 1) If a parameter is passed with a value, set the session variable with
> that
> value;
>
> 2) If a parameter is passed with an empty value, get rid of that session
> variable;
>
> 3) If a parameter is not passed at all (not referenced in the URL), don't
> touch the session variable.
>
> Tnx
> CL
>
> "Unrest" <unrest(at)nullvector(dot)org> wrote in message
> news:4dac7f92$0$68307$afc38c87(at)news5(dot)united-newsserver(dot)de...
>> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>>> <?php
>>> if (isset($_GET['x'])) {
>>> if ($_GET['x'] == null) {
>>> // it's null
>>> } else {
>>> // it has data
>>> }
>>> } else {
>>> // it's not defined
>>> }
>>> ?>
>>>
>>
>> isset() checks if a variable exists and _is not null_.
>> -> http://de.php.net/manual/en/function.isset.php
>>
>> so your "if ($_GET['x'] == null)" will never evaluate to true.
>>
>>
>> Yours,
>> Michael
>>
>
>
>
Re: Parameter passing question [message #173548 is a reply to message #173545] Mon, 18 April 2011 18:45 Go to previous messageGo to next message
Unrest is currently offline  Unrest
Messages: 10
Registered: April 2011
Karma: 0
Junior Member
Am Mon, 18 Apr 2011 20:28:28 +0200 schrieb Thomas 'PointedEars' Lahn:

>
> if (array_key_exists('x', $_GET))
> {
> if ($_GET['x'] == null)
> {
> // ...
> }
> }
>
> would make sense then.

ACK. :)

And combined:

*--- SNIP

if( isset($_GET['x'] ){
//we received the parameter with a value

}else{
if( array_key_exists( 'x', $_GET) ){
//we have a NULLed key

}else{
//we did not receive the parameter at all

}

}

*--- /SNIP


Yours,
Michael

PS: This costs you 1USD (.5USD for P.E. and .5USD for me)! ;)
Re: Parameter passing question [message #173549 is a reply to message #173542] Mon, 18 April 2011 18:54 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Mon, 18 Apr 2011 14:20:00 -0400, Chuck Lavin wrote:

> "Denis McMahon" <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote in message
> news:4dac7807$0$23634$bed64819(at)gradwell(dot)net...
>> On Mon, 18 Apr 2011 13:03:24 -0400, Chuck Lavin wrote:
>>
>>> How do I tell these three passed parameters apart (PHP 5)?
>>
>>> http://www.somewhere.com?param=value // param has been set to
>>> 'value' http://www.somewhere.com?param= // param has been set to
>>> empty (or null)
>>> http://www.somewhere.com // param has not been set at all
>>
>> This smells like it might be a homework question, or someone doing a
>> w3schools online certification, but I'll bite.
>>
>> Have you tried something like the following:
>>
>> <?php
>> if (isset($_GET['x'])) {
>> if ($_GET['x'] == null) {
>> // it's null
>> } else {
>> // it has data
>> }
>> } else {
>> // it's not defined
>> }
>> ?>
>>
>> If you have tried it, did it do what you want, and if not how did it
>> fail to do so[1]?
>>
>> If you haven't tried it, what have you tried so far?
>>
>> If you can't figure out what to use for x, please ask your teacher to
>> revise passing parameters with you again.
>>
>> Rgds
>>
>> Denis McMahon
>>
>> [1] I don't think it quite does what you want, but I also think the
>> change that needs to be made is trivial and you should be able to
>> deduce it yourself.

This is a newsgroup. Reply goes at the bottom.

> This is not a homework assignment. I'm working on a live remote server
> that I'd rather not be playing around with.
>
> According to the PHP doc page for isset(), isset() can't tell the
> difference between a variable that's not set and a variable that's
> empty.
>
> I need to move passed parameters into session variables:
>
> 1) If a parameter is passed with a value, set the session variable with
> that value;
>
> 2) If a parameter is passed with an empty value, get rid of that session
> variable;
>
> 3) If a parameter is not passed at all (not referenced in the URL),
> don't touch the session variable.
>
> And right now I can't tell the difference between a parameter being
> passed empty and no parameter being passed at all.

Everything in the $_GET array is a string.

The following should work:

<?php
if (isset($_GET['x'])) {
if ($_GET['x'] === "") {
// an empty string
} else {
// a non empty string
}
} else {
// not defined
}
?>

Rgds

Denis McMahon
Re: Parameter passing question [message #173550 is a reply to message #173547] Mon, 18 April 2011 19:04 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Mon, 18 Apr 2011 14:34:33 -0400, Chuck Lavin wrote:

> "Chuck Lavin" <x(at)x(dot)x> wrote in message
> news:Qk%qp(dot)16994$7N3(dot)5715(at)newsfe10(dot)iad...
>> "Unrest" <unrest(at)nullvector(dot)org> wrote in message
>> news:4dac7f92$0$68307$afc38c87(at)news5(dot)united-newsserver(dot)de...
>>> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>>>> <?php
>>>> if (isset($_GET['x'])) {
>>>> if ($_GET['x'] == null) {
>>>> // it's null
>>>> } else {
>>>> // it has data
>>>> }
>>>> } else {
>>>> // it's not defined
>>>> }
>>>> ?>
>>>>
>>>>
>>> isset() checks if a variable exists and _is not null_. ->
>>> http://de.php.net/manual/en/function.isset.php
>>>
>>> so your "if ($_GET['x'] == null)" will never evaluate to true.

>> My point exactly. How can I tell if a URL does not reference a
>> parameter at all?
>>
>> I need to move passed parameters into session variables:
>>
>> 1) If a parameter is passed with a value, set the session variable with
>> that
>> value;
>>
>> 2) If a parameter is passed with an empty value, get rid of that
>> session variable;
>>
>> 3) If a parameter is not passed at all (not referenced in the URL),
>> don't touch the session variable.

> I have this IF statement:
>
> if (isset($_SESSION['COMPANY_CODE'])) {
> $COMPANY_CODE = $_SESSION['COMPANY_CODE'];
> } else {
> $query = parse_str($_SERVER['QUERY_STRING']); $COMPANY_CODE = $app;
> $_SESSION['COMPANY_CODE'] = $COMPANY_CODE;
> }
>
> It currently does the reverse of what I need it to do. This block gives
> precedence to the session variable. If the session variable exists, the
> passed parameter is ignored.
>
> I need to give precedence to the passed parameter. If the parameter is
> passed (either with a value or empty), I need to modify the session
> variable accordingly. If the parameter is not passed, I want to leave
> the session variable untouched.
>
> As I understand it, checking for isset($app) will not tell the
> difference between http://www.somewhere.com/?app= and
> http://www.somewhere.com .

<?php

// first set the value according to the session variable
// if set, else to an empty string

if (isset($_SESSION['COMPANY_CODE'])) {
$COMPANY_CODE = $_SESSION['COMPANY_CODE'];
} else {
$COMPANY_CODE = "";
}

// now over-ride the previous value with the value from the
// http get request if one is set

if (isset($_GET['app'])) {
if ($_GET['app'] === "") {
// app was an empty string
$COMPANY_CODE = "";
} else {
// app was non empty string
$COMPANY_CODE = $_GET['app'];
}
} else {
// app not defined in get
// leave variable alone alone
}

// finally, update the session variable to the current value

$_SESSION['COMPANY_CODE'] = $COMPANY_CODE;

?>

Rgds

Denis McMahon
Re: Parameter passing question [message #173551 is a reply to message #173549] Mon, 18 April 2011 19:07 Go to previous messageGo to next message
Unrest is currently offline  Unrest
Messages: 10
Registered: April 2011
Karma: 0
Junior Member
Am Mon, 18 Apr 2011 18:54:19 +0000 schrieb Denis McMahon:

> The following should work:
>
> <?php
> if (isset($_GET['x'])) {
> if ($_GET['x'] === "") {
> // an empty string
> } else {
> // a non empty string
> }
> } else {
> // not defined
> }
> ?>
>
> Rgds
>
> Denis McMahon

no it won't. have a look at the other "thread" in here.
his problem is solved there, too. even with commented code! ;)

sidenote: isset evaluates to true only if the variable exists and is not
null.
Re: Parameter passing question [message #173552 is a reply to message #173542] Mon, 18 April 2011 19:11 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 4/18/2011 2:20 PM, Chuck Lavin wrote:
> This is not a homework assignment. I'm working on a live remote server that
> I'd rather not be playing around with.
>
> According to the PHP doc page for isset(), isset() can't tell the difference
> between a variable that's not set and a variable that's empty.
>
> I need to move passed parameters into session variables:
>
> 1) If a parameter is passed with a value, set the session variable with that
> value;
>
> 2) If a parameter is passed with an empty value, get rid of that session
> variable;
>
> 3) If a parameter is not passed at all (not referenced in the URL), don't
> touch the session variable.
>
> And right now I can't tell the difference between a parameter being passed
> empty and no parameter being passed at all.

Uh, why do you care? If it is passed empty, then you get rid of it with
unset($_SESSION['the variable']. If it is not passed at all, and it
should have been if not empty, then do the unset as well. If it hadn't
been set, nothing happens.

So, why do care about the difference?

>
> Tnx
> CL
>
> "Denis McMahon"<denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote in message
> news:4dac7807$0$23634$bed64819(at)gradwell(dot)net...
>> On Mon, 18 Apr 2011 13:03:24 -0400, Chuck Lavin wrote:
>>
>>> How do I tell these three passed parameters apart (PHP 5)?
>>
>>> http://www.somewhere.com?param=value // param has been set to 'value'
>>> http://www.somewhere.com?param= // param has been set to empty (or
>>> null)
>>> http://www.somewhere.com // param has not been set at all
>>
>> This smells like it might be a homework question, or someone doing a
>> w3schools online certification, but I'll bite.
>>
>> Have you tried something like the following:
>>
>> <?php
>> if (isset($_GET['x'])) {
>> if ($_GET['x'] == null) {
>> // it's null
>> } else {
>> // it has data
>> }
>> } else {
>> // it's not defined
>> }
>> ?>
>>
>> If you have tried it, did it do what you want, and if not how did it fail
>> to do so[1]?
>>
>> If you haven't tried it, what have you tried so far?
>>
>> If you can't figure out what to use for x, please ask your teacher to
>> revise passing parameters with you again.
>>
>> Rgds
>>
>> Denis McMahon
>>
>> [1] I don't think it quite does what you want, but I also think the
>> change that needs to be made is trivial and you should be able to deduce
>> it yourself.
>>
>
>


--
Shelly
Re: Parameter passing question [message #173553 is a reply to message #173551] Mon, 18 April 2011 19:19 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Mon, 18 Apr 2011 19:07:46 +0000, Unrest wrote:

> sidenote: isset evaluates to true only if the variable exists and is not
> null.

An empty string doesn't equate to null if you use the right comparison
operator!

("" === null) returns false

so, test if the variable is set, and if it is set, test for empty string

Rgds

Denis McMahon
Re: Parameter passing question [message #173554 is a reply to message #173552] Mon, 18 April 2011 19:21 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Mon, 18 Apr 2011 15:11:10 -0400, sheldonlg wrote:

> On 4/18/2011 2:20 PM, Chuck Lavin wrote:
>> This is not a homework assignment. I'm working on a live remote server
>> that I'd rather not be playing around with.
>>
>> According to the PHP doc page for isset(), isset() can't tell the
>> difference between a variable that's not set and a variable that's
>> empty.
>>
>> I need to move passed parameters into session variables:
>>
>> 1) If a parameter is passed with a value, set the session variable with
>> that value;
>>
>> 2) If a parameter is passed with an empty value, get rid of that
>> session variable;
>>
>> 3) If a parameter is not passed at all (not referenced in the URL),
>> don't touch the session variable.
>>
>> And right now I can't tell the difference between a parameter being
>> passed empty and no parameter being passed at all.
>
> Uh, why do you care? If it is passed empty, then you get rid of it with
> unset($_SESSION['the variable']. If it is not passed at all, and it
> should have been if not empty, then do the unset as well. If it hadn't
> been set, nothing happens.
>
> So, why do care about the difference?

Uh, I think his requirement is:

If the param is set and empty, set session value to an empty string

If the param is set and contains data, set session value to data

If the param is not present, used a stored session value if one is present

I'm not sure what he wants to do if the param is not present and there's
no stored session param, but I assumed he'd accept an empty string in
that case too.

Rgds

Denis McMahon
Re: Parameter passing question [message #173556 is a reply to message #173553] Mon, 18 April 2011 19:40 Go to previous messageGo to next message
Unrest is currently offline  Unrest
Messages: 10
Registered: April 2011
Karma: 0
Junior Member
Am Mon, 18 Apr 2011 19:19:11 +0000 schrieb Denis McMahon:

> On Mon, 18 Apr 2011 19:07:46 +0000, Unrest wrote:
>
>> sidenote: isset evaluates to true only if the variable exists and is
>> not null.
>
> An empty string doesn't equate to null if you use the right comparison
> operator!
>
> ("" === null) returns false
>
> so, test if the variable is set, and if it is set, test for empty string
>
> Rgds
>
> Denis McMahon

SORRY ("big sorry"). Been a bit distracted when posting that.
You are, of course, right.

Michael
Re: Parameter passing question [message #173569 is a reply to message #173545] Tue, 19 April 2011 03:28 Go to previous messageGo to next message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma: 0
Member
Thomas 'PointedEars' Lahn <PointedEars(at)web(dot)de> wrote:

> Unrest wrote:
>
>> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>>> <?php
>>> if (isset($_GET['x'])) {
>>> if ($_GET['x'] == null) {
>>> // it's null
>>> } else {
>>> // it has data
>>> }
>>> } else {
>>> // it's not defined
>>> }
>>> ?>
>>>
>>
>> isset() checks if a variable exists and _is not null_.

Right.

>> -> http://de.php.net/manual/en/function.isset.php
>>
>> so your "if ($_GET['x'] == null)" will never evaluate to true.
>
> True.

Not quite, because, as far as I can tell, PHP will treat query
string parameters without values as empty strings within the
superglobals. Note that that the "==" operator doesn't perform
strict type checking, so a comparison with NULL will yield true
when compared with an empty string.

> if (array_key_exists('x', $_GET))
> {
> if ($_GET['x'] == null)

Here, using ``empty()'' may be clearer.

> {
> // ...
> }
> }
>
> would make sense then.

This approach is still a bit nicer, IMO. It more clearly shows
the intent of the author and is more versatile when handling
arrays in which the values can actually be NULL.

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
Re: Parameter passing question [message #173570 is a reply to message #173537] Tue, 19 April 2011 03:34 Go to previous messageGo to next message
Curtis Dyer is currently offline  Curtis Dyer
Messages: 34
Registered: January 2011
Karma: 0
Member
"Chuck Lavin" <x(at)x(dot)x> wrote:

> Hi --
>
> I'm having a problem understanding what would be the proper
> function to use here ...
>
> How do I tell these three passed parameters apart (PHP 5)?
>
> http://www.somewhere.com?param=value // param has been set to
> 'value'
>
> http://www.somewhere.com?param= // param has been set to
> empty (or null)
>
> http://www.somewhere.com // param has not been set at all

In addition to all the other replies, I thought you might still find
this PHP documentation resource especially helpful:

<http://php.net/manual/en/types.comparisons.php>

This page shows detailed type comparison tables for both loose and
strict comparisons.

--
Curtis Dyer
<?$x='<?$x=%c%s%c;printf($x,39,$x,39);?>';printf($x,39,$x,39);?>
Re: Parameter passing question [message #173598 is a reply to message #173550] Wed, 20 April 2011 06:49 Go to previous messageGo to next message
Chuck Lavin is currently offline  Chuck Lavin
Messages: 5
Registered: April 2011
Karma: 0
Junior Member
Thanks!

"Denis McMahon" <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote in message
news:4dac8b47$0$23634$bed64819(at)gradwell(dot)net...
> On Mon, 18 Apr 2011 14:34:33 -0400, Chuck Lavin wrote:
>
>> "Chuck Lavin" <x(at)x(dot)x> wrote in message
>> news:Qk%qp(dot)16994$7N3(dot)5715(at)newsfe10(dot)iad...
>>> "Unrest" <unrest(at)nullvector(dot)org> wrote in message
>>> news:4dac7f92$0$68307$afc38c87(at)news5(dot)united-newsserver(dot)de...
>>>> Am Mon, 18 Apr 2011 17:42:31 +0000 schrieb Denis McMahon:
>>>> > <?php
>>>> > if (isset($_GET['x'])) {
>>>> > if ($_GET['x'] == null) {
>>>> > // it's null
>>>> > } else {
>>>> > // it has data
>>>> > }
>>>> > } else {
>>>> > // it's not defined
>>>> > }
>>>> > ?>
>>>> >
>>>> >
>>>> isset() checks if a variable exists and _is not null_. ->
>>>> http://de.php.net/manual/en/function.isset.php
>>>>
>>>> so your "if ($_GET['x'] == null)" will never evaluate to true.
>
>>> My point exactly. How can I tell if a URL does not reference a
>>> parameter at all?
>>>
>>> I need to move passed parameters into session variables:
>>>
>>> 1) If a parameter is passed with a value, set the session variable with
>>> that
>>> value;
>>>
>>> 2) If a parameter is passed with an empty value, get rid of that
>>> session variable;
>>>
>>> 3) If a parameter is not passed at all (not referenced in the URL),
>>> don't touch the session variable.
>
>> I have this IF statement:
>>
>> if (isset($_SESSION['COMPANY_CODE'])) {
>> $COMPANY_CODE = $_SESSION['COMPANY_CODE'];
>> } else {
>> $query = parse_str($_SERVER['QUERY_STRING']); $COMPANY_CODE = $app;
>> $_SESSION['COMPANY_CODE'] = $COMPANY_CODE;
>> }
>>
>> It currently does the reverse of what I need it to do. This block gives
>> precedence to the session variable. If the session variable exists, the
>> passed parameter is ignored.
>>
>> I need to give precedence to the passed parameter. If the parameter is
>> passed (either with a value or empty), I need to modify the session
>> variable accordingly. If the parameter is not passed, I want to leave
>> the session variable untouched.
>>
>> As I understand it, checking for isset($app) will not tell the
>> difference between http://www.somewhere.com/?app= and
>> http://www.somewhere.com .
>
> <?php
>
> // first set the value according to the session variable
> // if set, else to an empty string
>
> if (isset($_SESSION['COMPANY_CODE'])) {
> $COMPANY_CODE = $_SESSION['COMPANY_CODE'];
> } else {
> $COMPANY_CODE = "";
> }
>
> // now over-ride the previous value with the value from the
> // http get request if one is set
>
> if (isset($_GET['app'])) {
> if ($_GET['app'] === "") {
> // app was an empty string
> $COMPANY_CODE = "";
> } else {
> // app was non empty string
> $COMPANY_CODE = $_GET['app'];
> }
> } else {
> // app not defined in get
> // leave variable alone alone
> }
>
> // finally, update the session variable to the current value
>
> $_SESSION['COMPANY_CODE'] = $COMPANY_CODE;
>
> ?>
>
> Rgds
>
> Denis McMahon
>
Re: Parameter passing question [message #173603 is a reply to message #173598] Wed, 20 April 2011 09:28 Go to previous message
Unrest is currently offline  Unrest
Messages: 10
Registered: April 2011
Karma: 0
Junior Member
Am Wed, 20 Apr 2011 02:49:22 -0400 schrieb Chuck Lavin:

> Thanks!
>
> "Denis McMahon" <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com> wrote in message
> news:4dac8b47$0$23634$bed64819(at)gradwell(dot)net...
>> On Mon, 18 Apr 2011 14:34:33 -0400, Chuck Lavin wrote:

This is a NEWSGROUP and not your typical Outlook-mail!
So: STOP TOP-POSTING!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: &amp; - form and session problem!
Next Topic: doctype not found?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 18:47:06 GMT 2024

Total time taken to generate the page: 0.02371 seconds