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 #173549 is a reply to message #173542] Mon, 18 April 2011 18:54 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
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
[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: Mon Nov 25 18:14:39 GMT 2024

Total time taken to generate the page: 0.08781 seconds