[UPHPU] Check boxes and sessions

David Smith DavidSmith at byu.net
Wed Sep 15 12:46:49 MDT 2004

My mistake. :)


<quote who="John">
> I see what your saying, but as Ash and I have worked together I figured he
> would remember that I always use session_register("session") as my global
> array.  So it's just a session array called "session".
> --
> Thanks
> John
>> Note that this will only work if register_globals is turned on, and that
>>  it's not $session['name_checkbox'], but rather
>> $_SESSION['name_checkbox']. The PHP documentation recommends that you
>> *either* use session_register() or access the $_SESSION array directly.
>> Do not mix the two. I recommend writing accessors functions for getting
>> at the $_SESSION array, like get_session_var() and set_session_var(),
>> and make those two functions ensure that the session is indeed started
>> prior to giving a result.
>> --Dave
>> John wrote:
>>>// you only have to register the session variable name once.
>>>// ie. session_register("name_checkbox");
>>>// as long as this has been done somewhere in some script, and
>>>// you session_start() at the begining of the script page, the
>>>// value will be constant.
>>>// you could also make them as $session['name_checkbox'];
>>>// and then just session_register("session");
>>><form ....>
>>><input type="checkbox" name="name_checkbox" value="1">
>>><input type="checkbox" name="address_checkbox" value="1">
>>>if ($name_checkbox == "1")
>>>    ..do something...
>>>Ash, if this isn't clear let me know and I'll make a much more detailed
>>> example.  Basically there are 3 parts.  1) make sure the session is
>>> started on each page.  2) make sure that at least somewhere the script
>>> is told to register the variable name of your choice into the saved
>>> session data.  3) obtain the form value (in my example it's "1"), and
>>> assign the form data to the session var name, and that should be enough
>>> to make it work.
>>>>What is the best way to take a checkbox value through a php session?
>>>>For example, I have a page that has name, address, phone, zip, city,
>>>> zip, etc.
>>>>There's a checkbox next to each one that the person will check if they
>>>> want that info to print on the next page and the page after that.
>>>> Basically the rest of the time they're on the site.
>>>>How do I tell if the checkbox has been checked using sessions?

More information about the UPHPU mailing list