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
Return to the default flat view Create a new topic Submit Reply
Re: Parameter passing question [message #173598 is a reply to message #173550] Wed, 20 April 2011 06:49 Go to previous messageGo to previous message
Chuck Lavin is currently offline  Chuck Lavin
Messages: 5
Registered: April 2011
Karma:
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
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: &amp; - form and session problem!
Next Topic: doctype not found?
Goto Forum:
  

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

Current Time: Fri Nov 29 08:28:15 GMT 2024

Total time taken to generate the page: 0.03522 seconds