allasso Posted November 28, 2008 Share Posted November 28, 2008 I have had no success in passing the $_SESSION["var"] array to other pages. I have included code that looks something like below, with session_start() at the very top of the script, and not html above it. (no output sent before session_start() ). I have also included session_start() on all pages I wish to retrieve the variables from. No success. <?php session_start(); $_SESSION["var"] = 'hello world'; ?> any ideas? Thanks, Allasso Report this post Quote Link to comment Share on other sites More sharing options...
vicodin Posted November 28, 2008 Share Posted November 28, 2008 Try: $_SESSION['var'] = 'Hello World'; So instead of " use ' ... Make sure you have session_start() on all your pages that will be in the session. Quote Link to comment Share on other sites More sharing options...
.josh Posted November 28, 2008 Share Posted November 28, 2008 If there is no html output before the session_start(), not even blank lines or whitespace, then there's no reason that code shouldn't create that session var. Quote Link to comment Share on other sites More sharing options...
ShiloVir Posted November 29, 2008 Share Posted November 29, 2008 PAGE1.PHP: <?php session_start(); $_SESSION["var"] = 'hello world'; ?> PAGE2.PHP <?php session_start(); echo $_SESSION["var"]; ?> I dont understand why its not being passed??? Double check u got session_start(); at top of each page with the session data. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2008 Share Posted November 29, 2008 Add the following two lines of code immediately after your first <?php tag on each page to get php to help you - ini_set ("display_errors", "1"); error_reporting(E_ALL); Alternatively, you should be learning php or learning anything new in php, developing php code, or debugging php code on a system where those two settings have been set in php.ini. That way you won't need to remember to remove those two lines when you put your code onto a live server. Stop and start your web server to get any changes made to php.ini to take effect. Quote Link to comment Share on other sites More sharing options...
haku Posted November 29, 2008 Share Posted November 29, 2008 If you don't give the code on the page it's supposed to output on, we can't tell you why it isn't being outputted. Quote Link to comment Share on other sites More sharing options...
allasso Posted November 30, 2008 Author Share Posted November 30, 2008 PFMaBiSmAd: good suggestion, I"ll start doing that. haku: good point :-) Sounds like it probably isn't a big mystery, most likely just inexperience. I'll keep playing with it. Thanks All Quote Link to comment Share on other sites More sharing options...
allasso Posted November 30, 2008 Author Share Posted November 30, 2008 the problem was that I was using integers as keys in the $_SESSION[] array. Apparently you can't do that unless they are mixed with alpha characters. Couldn't find anything about that in the manual, but maybe it is in there somewhere. But it was sure obvious that it worked when I used alpha, and didn't when I didn't. I tried it several times. When I posted my code, I was on a different system, so I just posted something "generic", thus using "var" for a key. I see it is sure important to post the code just as it is written. Sorry. Thanks all, Allasso Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.