[UPHPU] Check boxes and sessions

Dave Smith DavidSmith at byu.net
Wed Sep 15 06:30:38 MDT 2004


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:

><?PHP
>session_start()
>// 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");
>
>session_register("name_checkbox");
>session_register("address_checkbox")
>session_register("etc.etc.");
>
>?>
>
><form ....>
><input type="checkbox" name="name_checkbox" value="1">
><input type="checkbox" name="address_checkbox" value="1">
></form>
>
>
><?PHP
>if ($name_checkbox == "1")
>    ..do something...
>
>etc
>?>
>
>
>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.
>
>--
>Thanks
>John
>
>  
>
>>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?
>>
>>Ash
>>
>>
>>
>>--------------------------------------------------------------------- To
>>unsubscribe, e-mail: list-unsubscribe at uphpu.org
>>For additional commands, e-mail: list-help at uphpu.org
>>    
>>
>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: list-unsubscribe at uphpu.org
>For additional commands, e-mail: list-help at uphpu.org
>
>  
>




More information about the UPHPU mailing list