Jump to content

[SOLVED] $_SESSION[] variable not being passed


allasso

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.