[PHP] string to array?
Hi all, I have a string something like "10.2.3" I want to be able to use the "." as a delimiter to reference the elements (10, 2, and 3). My thought was to create an array, using "." as the delimiter. Is there a function that will create an array out of a string, using a delimiter you specify? I seem to have read something like that, but I can't find it now. Any other ideas would be welcome. TIA --Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] newbie question - retaining values
Hi, I've been creating forms that use hidden inputs to retain variables and values from one instance of the form to the next (by calling itself in the FORM ACTION). Are there other ways to retain *global* variables and values between instances of loading a page? I apologize for the newbie question, I'm still trying to grasp the concepts of programming for the web environment. TIA, Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] sessions help
Hi again. Thanks to Miguel and Matt for pointing me to sessions for retaining variables. I've got the register_globals directive set to Off. I want to store a value in a session variable. I've set up two documents (one that sets a session variable, and one that retrieves it), with the following code. In doc 1, I've got this code: function sessionSetNode ($node_id) { return ($_SESSION['node'] = $node_id); } sessionSetNode("10.2"); Doc 2 looks like this: if (!empty($_SESSION)) { extract($_SESSION); } else if (!empty($HTTP_SESSION_VARS)) { extract($HTTP_SESSION_VARS); } function sessionGetNode () { return $_SESSION['node']; } $n = sessionGetNode(); echo ("Node is $n."); First, I load Doc 1 (to set the session variable). Then I load Doc 2 to retrieve the variable. When doc 2 runs, I get the following: -- Warning: Undefined variable: _SESSION in c:\...\getsessionvar.php on line 17 Node is . -- Line 17 is the } after the line return $_SESSION['node']; It doesn't seem to know about $_SESSION. Can someone help me out? TIA, Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sessions help
I just tried adding session_start() to the beginning of both files. When I load Doc 1, I get this warning twice(!): Warning: Cannot send session cache limiter - headers already sent (output started at c:\program files\apache group\apache\htdocs\wan\sessions.php:7) in c:\program files\apache group\apache\htdocs\wan\sessions.php on line 9 Same warning for Doc 2. 8-| ??? At 02:57 PM 6/13/2002, you wrote: >On Thursday, June 13, 2002 at 9:46:10 PM, you wrote: > > First, I load Doc 1 (to set the session variable). > > Then I load Doc 2 to retrieve the variable. When doc 2 runs, I get the > > following: > > > >-- > > Warning: Undefined variable: _SESSION in c:\...\getsessionvar.php on > line 17 > > Node is . > > > >-- > > Line 17 is the } after the line return $_SESSION['node']; > > > It doesn't seem to know about $_SESSION. > > Can someone help me out? > >Do you have a call to start_session() at the top of both files? If not, that's >what's missing. > >-- >Stuart -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] sessions help
It's the 1st line after LD> I just tried adding session_start() to the beginning of both files. >When I >LD> load Doc 1, I get this warning twice(!): > >LD> Warning: Cannot send session cache limiter - headers already sent (output >LD> started at c:\program files\apache >group\apache\htdocs\wan\sessions.php:7) >LD> in c:\program files\apache group\apache\htdocs\wan\sessions.php on line 9 > >LD> Same warning for Doc 2. > > >That just means you put it in the wrong place. It has to go before >any (and "any" means ANY) output. > > >- Julie > >--> Julie Meloni >--> [EMAIL PROTECTED] >--> www.thickbook.com > >Find "Sams Teach Yourself MySQL in 24 Hours" at >http://www.amazon.com/exec/obidos/ASIN/0672323494/thickbookcom-20 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] sessions help
Thanks to Julie and Stuart for helping me. With your direction, I got rid of the warning about the headers by putting the session_start() at the beginning of the file. Now I get a different sort of error when I try to retrive the session variable: --- Warning: Undefined index: node in c:\program files\apache group\apache\htdocs\wan\getglobal.php on line 17 --- Any ideas why? (Here's the exact code I've got) [sessions.php] A test [getglobal.php] A test TIA, Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[2]: [PHP] sessions help
At 03:32 PM 6/13/2002, you wrote: >Thanks to Julie and Stuart for helping me. > >With your direction, I got rid of the warning about the headers by putting >the session_start() at the beginning of the file. > >Now I get a different sort of error when I try to retrive the session >variable: >--- >Warning: Undefined index: node in c:\program files\apache >group\apache\htdocs\wan\getglobal.php on line 17 >--- > >Any ideas why? > >(Here's the exact code I've got) This is the code, w/o formatting, and w/o the html tags. Sorry about the formatting in the email >[sessions.php] > >$node_id); } sessionSetNode("10.2"); ?> >[getglobal.php] > >(!empty($HTTP_SESSION_VARS)) { extract($HTTP_SESSION_VARS); } function >sessionGetNode () { return $_SESSION['node']; } $n = sessionGetNode(); >echo ("Node is $n."); ?> > >TIA, >Leston > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re[3]: [PHP] sessions help
I've stripped the code down to barest bones to try to figure this out: [getglobal.php] ... echo "Node is {$_SESSION['node']}."; ... [session.php] ... $_SESSION['node'] = "10.2"; ... Other than the standard html, head, title, body tags and the session_start(), there is no other code. I'm still getting the "...Undefined index: node ..." warning. >Do a print_r($_SESSION); in getglobal.php to see what the session contains. It is: Array() > >if (!empty($_SESSION)) { > >extract($_SESSION); > >} else if (!empty($HTTP_SESSION_VARS)) { > >extract($HTTP_SESSION_VARS); > >} > >Why are you doing this? If you're accessing the session through $_sESSION then >there's no need to extract the session into the global scope. With register_globals=Off, I understand that you need to extract the $_POST and $_GET vars. I assumed the same for $_SESSIONS. Is this not true? TIA, Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[3]: [PHP] sessions help
Yeah, I thought of that too. Same result, though. At 04:16 PM 6/13/2002, you wrote: >Hmm. Okay. Replace $_SESSION with $HTTP_SESSION_VARS and see if that >works. >-Kevin > >- Original Message - >From: "Leston Drake" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Thursday, June 13, 2002 4:07 PM >Subject: Re[3]: [PHP] sessions help > > > > I've stripped the code down to barest bones to try to figure this out: > > [getglobal.php] > > ... > > echo "Node is {$_SESSION['node']}."; > > ... > > > > [session.php] > > ... > > $_SESSION['node'] = "10.2"; > > ... > > > > Other than the standard html, head, title, body tags and the > > session_start(), there is no other code. > > I'm still getting the "...Undefined index: node ..." warning. > > > > > > >Do a print_r($_SESSION); in getglobal.php to see what the session >contains. > > > > It is: Array() > > > > > >if (!empty($_SESSION)) { > > > >extract($_SESSION); > > > >} else if (!empty($HTTP_SESSION_VARS)) { > > > >extract($HTTP_SESSION_VARS); > > > >} > > > > > >Why are you doing this? If you're accessing the session through $_sESSION >then > > >there's no need to extract the session into the global scope. > > > > With register_globals=Off, I understand that you need to extract the >$_POST > > and $_GET vars. I assumed the same for $_SESSIONS. Is this not true? > > > > TIA, > > Leston > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re[4]: [PHP] sessions help
At 04:35 PM 6/13/2002, you wrote: >Have you tried this on a separate web page to make sure it's not something >server specific? No, but that's a good idea. I will try it. >Here's a script that worked from my computer with register_globals set to on >and off (restarted server between tests for confirmation). Did you send some code? I didn't receive any...? >If this works from your computer, could you resend the code on your page? > >Thanks, > >-Ed Thanks for your help, Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: Re[4]: [PHP] sessions help
Hey, it worked on another server! I've been working on my local machine's server (localhost), but when I run it from a different web server, it worked fine. Any ideas about which setting(s) may be causing the problem? From my php.ini file: session.save_handler=files session.save_path= C:\PHP\sessiondata session.use_cookies=1 session.name=PHPSESSID session.auto_start=0 session.cookie_lifetime=0 session.cookie_path=/ session.cookie_domain= session.serialize_handler=php session.gc_probability=1 session.gc_maxlifetime=1440 session.referer_check= session.entropy_length=0 session.entropy_file= session.cache_limiter=nocache session.cache_expire=180 session.use_trans_sid=1 At 04:35 PM 6/13/2002, you wrote: >Have you tried this on a separate web page to make sure it's not something >server specific? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] sessions trouble
Hello, I am unable to retrieve session variables on my local server. I'm using some code like this to test it (thanks to Ed): -- session_start(); echo ":" . $_SESSION["node"] . ""; $_SESSION["node"] = "10.2"; echo ":" . $_SESSION["node"] . ""; -- Then there is an href link to the same document, to test whether or not it can see $_SESSION["node"] the next time. It can't. The output for both requests looks like this: -- Warning: Undefined index: node in c:\program files\apache group\apache\htdocs\test5.php on line 3 : :10.2 test -- On another server (http://www.lpsoftware.com/phptest/test5.php) it works as expected. But I can't figure out why it doesn't work here. I'm running WinME, Apache 1.3.2, Php 4.1.2 I have cookies enabled (actually prompted so I can 'see' it) for my browser. Is there some setting in php.ini that I need to change? BTW, being a php newbie I really appreciate the helpful people on this list! You're a great resource. TIA, Leston -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sessions trouble
Actually, I've tried it both ways (register_globals=On and register_globals=Off). Same result with either setting. At 12:19 PM 6/18/2002, you wrote: >Check the register_globals setting in php.ini. It looks like it is "on" on >the problem server. If so, then you have two choices: >1. Turn it "off" >2. Change your code to this style: > >session_start(); >$node = 10.2; >session_register('node'); >echo $node; > >Kirk > > > -Original Message- > > From: Leston Drake [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, June 18, 2002 11:48 AM > > To: [EMAIL PROTECTED] > > Subject: [PHP] sessions trouble > > > > > > Hello, > > > > I am unable to retrieve session variables on my local server. > > I'm using some code like this to test it (thanks to Ed): > > -- > > session_start(); > > echo ":" . $_SESSION["node"] . ""; > > $_SESSION["node"] = "10.2"; > > echo ":" . $_SESSION["node"] . ""; > > -- > > > > Then there is an href link to the same document, to test > > whether or not it > > can see $_SESSION["node"] the next time. > > It can't. > > The output for both requests looks like this: > > -- > > Warning: Undefined index: node in c:\program files\apache > > group\apache\htdocs\test5.php on line 3 > > : > > :10.2 > > > > test > > -- > > > > On another server >(http://www.lpsoftware.com/phptest/test5.php) it works as >expected. But I can't figure out why it doesn't work here. >I'm running WinME, Apache 1.3.2, Php 4.1.2 > >I have cookies enabled (actually prompted so I can 'see' it) for my browser. >Is there some setting in php.ini that I need to change? > >BTW, being a php newbie I really appreciate the helpful people on this >list! You're a great resource. > >TIA, >Leston > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sessions trouble
I have register_globals=Off (which is what I prefer to program for). But if I change register_globals to On, and use the session_register() function, it works. With register_globals Off, using $_SESSION doesn't work. I thought that $_SESSION would work regardless of whether register_globals was On or Off. At 12:19 PM 6/18/2002, you wrote: >Check the register_globals setting in php.ini. It looks like it is "on" on >the problem server. If so, then you have two choices: >1. Turn it "off" >2. Change your code to this style: > >session_start(); >$node = 10.2; >session_register('node'); >echo $node; > >Kirk > > > -Original Message- > > From: Leston Drake [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, June 18, 2002 11:48 AM > > To: [EMAIL PROTECTED] > > Subject: [PHP] sessions trouble > > > > > > Hello, > > > > I am unable to retrieve session variables on my local server. > > I'm using some code like this to test it (thanks to Ed): > > -- > > session_start(); > > echo ":" . $_SESSION["node"] . ""; > > $_SESSION["node"] = "10.2"; > > echo ":" . $_SESSION["node"] . ""; > > -- > > > > Then there is an href link to the same document, to test > > whether or not it > > can see $_SESSION["node"] the next time. > > It can't. > > The output for both requests looks like this: > > -- > > Warning: Undefined index: node in c:\program files\apache > > group\apache\htdocs\test5.php on line 3 > > : > > :10.2 > > > > test > > -- > > > > On another server >(http://www.lpsoftware.com/phptest/test5.php) it works as >expected. But I can't figure out why it doesn't work here. >I'm running WinME, Apache 1.3.2, Php 4.1.2 > >I have cookies enabled (actually prompted so I can 'see' it) for my browser. >Is there some setting in php.ini that I need to change? > >BTW, being a php newbie I really appreciate the helpful people on this >list! You're a great resource. > >TIA, >Leston > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sessions trouble
Ok, tried that. No difference. At 12:49 PM 6/18/2002, you wrote: >Try using the fuction session_write_close() after your done setting the >session vars. > >dunno but it might work :) > >Rick >- Original Message - >From: "Leston Drake" <[EMAIL PROTECTED]> >To: "Johnson, Kirk" <[EMAIL PROTECTED]> >Cc: <[EMAIL PROTECTED]> >Sent: Tuesday, June 18, 2002 1:28 PM >Subject: RE: [PHP] sessions trouble > > > > > > I have register_globals=Off (which is what I prefer to program for). > > But if I change register_globals to On, and use the session_register() > > function, it works. > > With register_globals Off, using $_SESSION doesn't work. > > I thought that $_SESSION would work regardless of whether register_globals > > was On or Off. > > > > At 12:19 PM 6/18/2002, you wrote: > > >Check the register_globals setting in php.ini. It looks like it is "on" >on > > >the problem server. If so, then you have two choices: > > >1. Turn it "off" > > >2. Change your code to this style: > > > > > >session_start(); > > >$node = 10.2; > > >session_register('node'); > > >echo $node; > > > > > >Kirk > > > > > > > -Original Message- > > > > From: Leston Drake [mailto:[EMAIL PROTECTED]] > > > > Sent: Tuesday, June 18, 2002 11:48 AM > > > > To: [EMAIL PROTECTED] > > > > Subject: [PHP] sessions trouble > > > > > > > > > > > > Hello, > > > > > > > > I am unable to retrieve session variables on my local server. > > > > I'm using some code like this to test it (thanks to Ed): > > > > -- > > > > session_start(); > > > > echo ":" . $_SESSION["node"] . ""; > > > > $_SESSION["node"] = "10.2"; > > > > echo ":" . $_SESSION["node"] . ""; > > > > -- > > > > > > > > Then there is an href link to the same document, to test > > > > whether or not it > > > > can see $_SESSION["node"] the next time. > > > > It can't. > > > > The output for both requests looks like this: > > > > -- > > > > Warning: Undefined index: node in c:\program files\apache > > > > group\apache\htdocs\test5.php on line 3 > > > > : > > > > :10.2 > > > > > > > > test > > > > -- > > > > > > > > On another server > > >(http://www.lpsoftware.com/phptest/test5.php) it works as > > >expected. But I can't figure out why it doesn't work here. > > >I'm running WinME, Apache 1.3.2, Php 4.1.2 > > > > > >I have cookies enabled (actually prompted so I can 'see' it) for my >browser. > > >Is there some setting in php.ini that I need to change? > > > > > >BTW, being a php newbie I really appreciate the helpful people on this > > >list! You're a great resource. > > > > > >TIA, > > >Leston > > > > > > > > >-- > > >PHP General Mailing List (http://www.php.net/) > > >To unsubscribe, visit: http://www.php.net/unsub.php > > > > > >-- > > >PHP General Mailing List (http://www.php.net/) > > >To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sessions trouble
I am using PHP 4.1.2, which I assume supports the $_SESSION global array. I've tried ...sigh... using $HTTP_SESSION_VARS, with the same result, unfortunately. At 02:12 PM 6/18/2002, you wrote: >Is your version of PHP new enough to support the new $_SESSION[] array? If >it is not, use $HTTP_SESSION_VARS[]. > > > -Original Message----- > > From: Leston Drake [mailto:[EMAIL PROTECTED]] > > Sent: Tuesday, June 18, 2002 12:29 PM > > To: Johnson, Kirk > > Cc: [EMAIL PROTECTED] > > Subject: RE: [PHP] sessions trouble > > > > > > > > I have register_globals=Off (which is what I prefer to program for). > > But if I change register_globals to On, and use the > > session_register() > > function, it works. > > With register_globals Off, using $_SESSION doesn't work. > > I thought that $_SESSION would work regardless of whether > > register_globals > > was On or Off. > > > > At 12:19 PM 6/18/2002, you wrote: > > >Check the register_globals setting in php.ini. It looks like > > it is "on" on > > >the problem server. If so, then you have two choices: > > >1. Turn it "off" > > >2. Change your code to this style: > > > > > >session_start(); > > >$node = 10.2; > > >session_register('node'); > > >echo $node; > > > > > >Kirk > > > > > > > -Original Message- > > > > From: Leston Drake [mailto:[EMAIL PROTECTED]] > > > > Sent: Tuesday, June 18, 2002 11:48 AM > > > > To: [EMAIL PROTECTED] > > > > Subject: [PHP] sessions trouble > > > > > > > > > > > > Hello, > > > > > > > > I am unable to retrieve session variables on my local server. > > > > I'm using some code like this to test it (thanks to Ed): > > > > -- > > > > session_start(); > > > > echo ":" . $_SESSION["node"] . ""; > > > > $_SESSION["node"] = "10.2"; > > > > echo ":" . $_SESSION["node"] . ""; > > > > -- > > > > > > > > Then there is an href link to the same document, to test > > > > whether or not it > > > > can see $_SESSION["node"] the next time. > > > > It can't. > > > > The output for both requests looks like this: > > > > -- > > > > Warning: Undefined index: node in c:\program files\apache > > > > group\apache\htdocs\test5.php on line 3 > > > > : > > > > :10.2 > > > > > > > > test > > > > -- > > > > > > > > On another server > > >(http://www.lpsoftware.com/phptest/test5.php) it works as > > >expected. But I can't figure out why it doesn't work here. > > >I'm running WinME, Apache 1.3.2, Php 4.1.2 > > > > > >I have cookies enabled (actually prompted so I can 'see' it) > > for my browser. > > >Is there some setting in php.ini that I need to change? > > > > > >BTW, being a php newbie I really appreciate the helpful > > people on this > > >list! You're a great resource. > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php