473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

My SESSION array does not PERSIST???

Hi all,

I am trying to store data in a $_SESSION variable (an array), but it reverts to
empty every time my page is refreshed (due to a submit button click).

I read the answer to the post "$_SESSION comes empty on next page" dated
2/4, whaich seems to be my problem. But the suggestions do not help me at all
<see 1 & 2 below>

1-have you set session.save_path ?
2-if you are using virtualhosts put this at the top of your .php file:
session_set_cookie_params(3200, '/', $_SERVER['HTTP_HOST']);
I have tested the array $_SESSION['list_array'] with both empty and !isset
and it returns true in both cases after a page refresh or when moving to
another page all together.

Is there something that I am missing...here is some of my code:

<?php

if (!isset($_POST['build_it'])) // if this is not the final submit, but
the first form display or redisplay
{
if (isset($_POST['add'])) // this is just the posting to the array
{
if (empty($_SESSION['list_array']))
{
$_SESSION['list_array'] = array(1 => $_POST['list_member']);
print "created and added...<br />";
}
else
{
$_SESSION['list_array'][] = $_POST['list_member'];
print "added...<br />";
}
print_r ($_SESSION['list_array']);
}

TIA,
Miki
Jul 17 '05 #1
3 4695
Is session.auto_start set to 1 in php.ini? If not, then settings $_SESSION
will have no effect and the array will remain empty. Call session_start() at
the beginning of your script.

Uzytkownik "Michelle" <miki@spam_me.net> napisal w wiadomosci
news:pMWVb.214147$nt4.995530@attbi_s51...
Hi all,

I am trying to store data in a $_SESSION variable (an array), but it reverts to empty every time my page is refreshed (due to a submit button click).

I read the answer to the post "$_SESSION comes empty on next page" dated
2/4, whaich seems to be my problem. But the suggestions do not help me at all <see 1 & 2 below>

1-have you set session.save_path ?
2-if you are using virtualhosts put this at the top of your .php file:
session_set_cookie_params(3200, '/', $_SERVER['HTTP_HOST']);
I have tested the array $_SESSION['list_array'] with both empty and !isset
and it returns true in both cases after a page refresh or when moving to
another page all together.

Is there something that I am missing...here is some of my code:

<?php

if (!isset($_POST['build_it'])) // if this is not the final submit, but
the first form display or redisplay
{
if (isset($_POST['add'])) // this is just the posting to the array
{
if (empty($_SESSION['list_array']))
{
$_SESSION['list_array'] = array(1 => $_POST['list_member']);
print "created and added...<br />";
}
else
{
$_SESSION['list_array'][] = $_POST['list_member'];
print "added...<br />";
}
print_r ($_SESSION['list_array']);
}

TIA,
Miki

Jul 17 '05 #2
Chung Leong wrote:
Is session.auto_start set to 1 in php.ini? If not, then settings $_SESSION
will have no effect and the array will remain empty. Call session_start() at
the beginning of your script.

Uzytkownik "Michelle" <miki@spam_me.net> napisal w wiadomosci
news:pMWVb.214147$nt4.995530@attbi_s51...
Hi all,

I am trying to store data in a $_SESSION variable (an array), but it


reverts to
empty every time my page is refreshed (due to a submit button click).

I read the answer to the post "$_SESSION comes empty on next page" dated
2/4, whaich seems to be my problem. But the suggestions do not help me at


all
<see 1 & 2 below>

1-have you set session.save_path ?
2-if you are using virtualhosts put this at the top of your .php file:
session_set_cookie_params(3200, '/', $_SERVER['HTTP_HOST']);
I have tested the array $_SESSION['list_array'] with both empty and !isset
and it returns true in both cases after a page refresh or when moving to
another page all together.

Is there something that I am missing...here is some of my code:

<?php

if (!isset($_POST['build_it'])) // if this is not the final submit, but
the first form display or redisplay
{
if (isset($_POST['add'])) // this is just the posting to the array
{
if (empty($_SESSION['list_array']))
{
$_SESSION['list_array'] = array(1 => $_POST['list_member']);
print "created and added...<br />";
}
else
{
$_SESSION['list_array'][] = $_POST['list_member'];
print "added...<br />";
}
print_r ($_SESSION['list_array']);
}

TIA,
Miki


Thanks...I just found out that session_start() is mandatory on every page that uses session vars.
Too bad the PHP.net docs don't say this, nor does my text "PHP and MySQL Web Development" by Welling
and Thomson...in fact the text says that it is just a good idea to use session_start() on a page
that accesses session vars...hmmm!

Thanks, again this group is great!
Jul 17 '05 #3
Thanks...I just found out that session_start() is mandatory on every page that uses session vars. Too bad the PHP.net docs don't say this, nor does my text "PHP and MySQL Web Development" by Welling and Thomson...in fact the text says that it is just a good idea to use session_start() on a page that accesses session vars...hmmm!

your text does say it, I have it too.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kid A | last post by:
I am developing a Struts1.1 based application, that returns an Excel File generated by Jakarta's POI classes. One of the requirements is that the file be stored in the SESSION ONLY, not on the...
14
by: dale zhang | last post by:
Hi groups, Can anyone give me the equivalent C# sharp code for this VB.ET code, :: VB.NET :: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles...
1
by: samtran331 | last post by:
Hi all I've got a .Net site that has 3 session variables...the variables should persist over 23 unique insert pages, 23 update, and 23 "view total" pages... And the problem is once I get past one...
3
by: grooby | last post by:
I would like to develop an asp.net Web application using muliple web projects under one solution file and share the session information between web applications( or projects). Is this possible?
3
by: Mark | last post by:
Ok, I know that .net inherently does not share session data across asp.net projects, but is there any decent work around to this. We already have a big chunk of our application using the asp.net...
8
by: bdeviled | last post by:
I am deploying to a web environment that uses load balancing and to insure that sessions persist across servers, the environment uses SQL to manage sessions. The machine.config file determines how...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
6
by: christopher.j.just | last post by:
I need to set the information being passed through the fields (23 of them) in the form into a session. Where do I start? Thanks, Chris
6
by: Joseph I. Ceasar | last post by:
I have an ASP .Net 2.0 site that I am working on. It has a master page and a content page. I also created a separate class module that returns a DataSet to feed my GridView. So far, so good. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.