logo       

RE: Session variables and arrays: msg#00724

Subject: RE: Session variables and arrays
Here are the results:

is_array():
gettype():string
strlen():5

> -----Original Message-----
> From: Peter Beckman [mailto:beckman@xxxxxxxxxxxxx] 
> Sent: Wednesday, October 30, 2002 8:57 AM
> To: Ryan Neudorf
> Cc: php-db@xxxxxxxxxxxxx
> Subject: RE: [PHP-DB] Session variables and arrays
> 
> 
> On Wed, 30 Oct 2002, Ryan Neudorf wrote:
> 
> > Ok. The categories are coming from checkboxes, e.g.:
> > <input type="checkbox" name="categories[]" value="1"  
> />Accountant<br 
> > />
> >
> > Which then are handled by a $cgi class dealy and handed to the 
> > $_SESSION['categories'] variable before being forwarded to the next 
> > step. I was thinking that the problem might be with the 
> $cgi object, 
> > but when I print_r($_SESSION['categories']) it shows the 
> contents of 
> > the array.
> >
> > Anyways, I did the print ":::{$_SESSION['categories']}:::"; and got
> > :::Array:::
> 
>  Try this after that print:
> 
>  print is_array($_SESSION['categories']);
> 
>  You should get a 1 -- if you don't, try this:
> 
>  print gettype($_SESSION['categories']);
> 
>  You should get "array" but if you don't, there is something 
> strange going  on!  If you get "string" though, do this:
> 
>  print strlen($_SESSION['categories']);
> 
>  If you get "5", then the variable might be a string with the 
> contents  being the word "Array".  Pretty doubtful, but we're 
> being thorough here.
> 
> Peter
> 
> > Hmph
> >
> > - Ryan
> >
> > > -----Original Message-----
> > > From: Peter Beckman [mailto:beckman@xxxxxxxxxxxxx]
> > > Sent: Tuesday, October 29, 2002 9:59 PM
> > > To: Ryan Neudorf
> > > Cc: php-db@xxxxxxxxxxxxx
> > > Subject: Re: [PHP-DB] Session variables and arrays
> > >
> > >
> > > Well, can't say I see the same problem:
> > >
> > > <?php
> > > $_SESSION['foo'] = array("hi"=>"bye");
> > >
> > > print_r($_SESSION['foo']);
> > > echo "\n\n";
> > > print is_array($_SESSION['foo']);
> > >
> > > Outputs:
> > > X-Powered-By: PHP/4.2.2
> > > Content-type: text/html
> > >
> > > Array
> > > (
> > >     [hi] => bye
> > > )
> > > 1
> > >
> > > Which is what I'd expect it to show.
> > >
> > > Now how did you assign categories?
> > >
> > > Maybe the var is a scalar and is actually "Array (\n  [0] 
> => '1';\n  
> > > [1] => '12';" and you are confused.o
> > >
> > > If you are saying:
> > >
> > > $_SESSION['categories'] = "Array (
> > >     [0] = '1';
> > >     ";
> > >
> > > Then it IS a scalar.  Try this:
> > >
> > > print ":::{$_SESSION['categories']}:::";
> > >
> > > If you get this:
> > >
> > > :::Array:::
> > >
> > > Then I have no clue what the problem is
> > >
> > > If you don't get that, then we know what your problem is.
> > >
> > > Peter
> > >
> > > On Tue, 29 Oct 2002, Ryan Neudorf wrote:
> > >
> > > > I'm having a problem with session variables and arrays. I'm 
> > > > building a multi step sign up form and I need to store all the 
> > > > variable until the final step, when they are inputed to a
> > > database. I
> > > > thought the best way to do this would be to store the 
> contents for 
> > > > $HTTP_POST_VARS in session variables. This works fine for
> > > everything
> > > > except for my array of checkboxes.
> > > >
> > > > When I do a print_r($_SESSION) it displays the 
> following for the 
> > > > sessionvariable assigned to the checkboxes: 
> [categories] => Array (
> > > >         [0] => '1';
> > > >         [1] => '12';
> > > > ... Etc ...
> > > >
> > > > But when I run any sort of array function (is_array, 
> foreach) on 
> > > > $_SESSION['categories'] it appears that it is a scalar, not
> > > an array.
> > > >
> > > > Any ideas?
> > > >
> > > > - Ryan
> > > >
> > > >
> > > > --
> > > > PHP Database Mailing List (http://www.php.net/)
> > > > To unsubscribe, visit: http://www.php.net/unsub.php
> > > >
> > >
> > > --------------------------------------------------------------
> > > -------------
> > > Peter Beckman            Systems Engineer, Fairfax Cable
> > > Access Corporation
> > > beckman@xxxxxxxxxxxxx
> > > http://www.purplecow.com/
> > >
> > > --------------------------------------------------------------
> > > -------------
> > >
> > >
> > > --
> > > PHP Database Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> --------------------------------------------------------------
> -------------
> Peter Beckman            Systems Engineer, Fairfax Cable 
> Access Corporation
> beckman@xxxxxxxxxxxxx                             
> http://www.purplecow.com/
> 
> --------------------------------------------------------------
> -------------
> 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
science.linguis...    culture.sf.lite...    video.mplayer.c...    yellowdog.gener...    ietf.rfc822/199...    emacs.help/2002...    redhat.release....    kernel.speakup/...    java.openejb.de...    debian.devel.gt...    xfree86.newbie/...    bug-tracking.ma...    pam/2003-05/msg...    games.devel.ope...    user-groups.lin...    music.pancham/2...    network.mq.deve...    web.html.genera...    arklinux.bugs/2...    linux.ecasound/...    qnx.openqnx.dev...    org.user-groups...    file-systems.sf...    trustix.contrib...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe