Re: Parameter passing question [message #173552 is a reply to message #173542] |
Mon, 18 April 2011 19:11 |
sheldonlg
Messages: 166 Registered: September 2010
Karma:
|
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
|
|
|