473,397 Members | 1,974 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,397 software developers and data experts.

Problem with session variables

This is a excerpt from the code where I collect data with a form.

<FORM action="index15dq.php" method="post" name="stegscf_pwd_edit"
id="stegscf_pwd_edit">

I am setting three session variables to already declared variables. I then
echo them and can see on the resulting form that they are set correctly.

<?
session_start();
$_SESSION['scf_upd_pwd'] = $scfmpwd1;
$_SESSION['scf_upd_num'] = $scfchknum;
$_SESSION['scf_upd_nam'] = $scfmfor;
echo $_SESSION['scf_upd_pwd'];
echo $_SESSION['scf_upd_num'];
echo $_SESSION['scf_upd_nam'];
?>

On the processing page - index15dq.php - I have this code.

<?
error_reporting(E_ALL);
session_start();
$scfmpwd1 = $_SESSION['scf_upd_pwd'];
$scfchknum = $_SESSION['scf_upd_num'];
$scfmfor = $_SESSION['scf_upd_nam'];
print "values";
echo $scfmpwd1;
echo $scfchknum;
echo $scfmfor;
?>

Its echoing blank values. No errors reported.

Shouldn't this work? How can I force session varables to work. Does it
matter where session_start is declared?

My pages are complex. First I open an index which looks at certain key
values, the page is then dynamicaly put together using segments of php code,
certain segments are omited or included according to which page is being
loaded. Much of these form the surrounding information, the headers, the
pictures and banners and the meny bar on the left of the screen.). All of
which can vary accordning to which page is being loaded.

Eventually the nitty-gritty of the page is loaded in the centre.

It is here that I am a) declaring loading the session variables.
and b) trying to use the loaded session variables.

Somewhere along the way they are being unloaded.

Garry Jones
Sweden
Oct 18 '06 #1
5 2244
Rik
Garry Jones wrote:
This is a excerpt from the code where I collect data with a form.

<FORM action="index15dq.php" method="post" name="stegscf_pwd_edit"
id="stegscf_pwd_edit">

I am setting three session variables to already declared variables. I
then echo them and can see on the resulting form that they are set
correctly.

<?
session_start();
$_SESSION['scf_upd_pwd'] = $scfmpwd1;
$_SESSION['scf_upd_num'] = $scfchknum;
$_SESSION['scf_upd_nam'] = $scfmfor;
echo $_SESSION['scf_upd_pwd'];
echo $_SESSION['scf_upd_num'];
echo $_SESSION['scf_upd_nam'];
>>

On the processing page - index15dq.php - I have this code.

<?
error_reporting(E_ALL);
session_start();
$scfmpwd1 = $_SESSION['scf_upd_pwd'];
$scfchknum = $_SESSION['scf_upd_num'];
$scfmfor = $_SESSION['scf_upd_nam'];
print "values";
echo $scfmpwd1;
echo $scfchknum;
echo $scfmfor;
>>

Its echoing blank values. No errors reported.

Shouldn't this work? How can I force session varables to work. Does it
matter where session_start is declared?

Yes. print_r($_SESSION); to check what your session actually holds.
Be warned that session_start() has to be declared BEFORE any output, or it
won't work. So not in 'the centre' of your page, but as one of the first
things 'on top'. Even sending out a simple space or line-break before
session_start() will render it useless.

Another word of advice: don't rely on shorttags: always use <?php instead
of <?
--
Grtz,

Rik Wasmus
Oct 18 '06 #2
"Rik" <lu************@hotmail.comskrev i meddelandet
news:a0***************************@news2.tudelft.n l...
Yes. print_r($_SESSION); to check what your session actually holds.
Be warned that session_start() has to be declared BEFORE any output, or it
won't work. So not in 'the centre' of your page, but as one of the first
things 'on top'. Even sending out a simple space or line-break before
session_start() will render it useless.
Done that and I am getting this. (Since I posted I turned error reporting on
in a setting my web hotel service allows users to change).

Warning: session_start() [function.session-start]: Cannot send session
cookie - headers already sent by (output started at
/customers/scfmotion.se/scfmotion.se/httpd.www/sitedefs.php:67) in
/customers/scfmotion.se/scfmotion.se/httpd.www/scfma_edt_pwd.php on line 34

Warning: session_start() [function.session-start]: Cannot send session cache
limiter - headers already sent (output started at
/customers/scfmotion.se/scfmotion.se/httpd.www/sitedefs.php:67) in
/customers/scfmotion.se/scfmotion.se/httpd.www/scfma_edt_pwd.php on line 34

So what does
"session cookie" and "session cache limiter" - mean?

Okay, it does seem like I have to move session_start somewhere else in the
code. Thats a bit of a nightmare because the code itself should only have
session_start based on a couple of conditions. These conditions are met when
that php code segment is called for. I am going to have to make a copy of
the very same if statements higher up and start the session earlier. That
should do it if I have understood you correctly.

Garry Jones
Oct 18 '06 #3
Rik
Garry Jones wrote:
Okay, it does seem like I have to move session_start somewhere else
in the code. Thats a bit of a nightmare because the code itself
should only have session_start based on a couple of conditions. These
conditions are met when that php code segment is called for. I am
going to have to make a copy of the very same if statements higher up
and start the session earlier. That should do it if I have understood
you correctly.
Indeed.
Things like headers, actions to take, etc, I usually do before any HTML
output at all.
--
Grtz,

Rik Wasmus
Oct 18 '06 #4
Rik" <lu************@hotmail.comskrev i meddelandet
news:76***************************@news2.tudelft.n l...
Garry Jones wrote:
Indeed.
Things like headers, actions to take, etc, I usually do before any HTML
output at all.
Hmmm I got one of my forms working. Did a similar thing to another one but
am still having problems

On the form page these two variables are echoed correctly.
<?= $_SESSION['scf_upd_num'] ?>
<?= $_SESSION['scf_upd_nam'] ?>

On the form page and the processing page I load the session start write at
the begining, first line of code.

But on the processing page these rows

error_reporting(E_ALL);
print_r($_SESSION);
echo $_SESSION['scf_upd_num'];
echo $_SESSION['scf_upd_nam'];

produce this output

Notice: Undefined variable: _SESSION in
/customers/scfmotion.se/scfmotion.se/httpd.www/cent15dt.php on line 5
Notice: Undefined variable: _SESSION in
/customers/scfmotion.se/scfmotion.se/httpd.www/cent15dt.php on line 6
Notice: Undefined variable: _SESSION in
/customers/scfmotion.se/scfmotion.se/httpd.www/cent15dt.php on line 7

Note that the form is processed by - FORM action="index15dt.php" - a file
which uses a segment called cent15dt.php which can be seen in the above
example. I am surprised to see the name of the segment in the code because
the index15dt.php is the start of the code that puts the entire page
together.

Any ideas?

Garry Jones
Sweden
Oct 18 '06 #5
Rik
Garry Jones wrote:
Notice: Undefined variable: _SESSION in
/customers/scfmotion.se/scfmotion.se/httpd.www/cent15dt.php on line 5

This is an error you'll get when you fail to give a correct
session_start(). This is mandatory on EVERY page. Be sure to:

- include session_start() in your script as one of the first command in
every file offcourse.
- enable error_reporting before the session_start();
- beware of type-errors :-)
--
Rik Wasmus
Oct 19 '06 #6

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

Similar topics

18
by: ZoombyWoof | last post by:
Hi. Im very new to php, and I have a problem here that I cant find the solution for. I have problems with session variables, I want some variables to maintain their value between different php...
13
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 ...
1
by: Jonathan Chong | last post by:
I have problem with AOL browser (IE and Netscape are OK) accessing my Web site after putting up a load balancer that will go to W1 or W2. The problem does not happen when there is only Web server...
3
by: Gary | last post by:
I am having a strange problem that I cannot solve. I have an asp page that I use for a user to login and gain access to other pages. When the user logs in I set a couple of session variables like...
7
by: Adam Short | last post by:
I'm having all sorts of problems with Sessions, I've been using them for years with out a hitch, all of a sudden the last 6 - 12 months since getting our new Win2003 server it's all gone shakey!!!...
5
by: Newton | last post by:
Hi, I got here the following problem. I am programming web application for examing students. After student will log on I need to keep his ID, Privileges, Login, Password for manipulating with...
6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
8
by: Ashish | last post by:
Incase the problem got bogged down reposting... Hi Gregory, I think I didnt make myself much clear. The problem is: 1. I have one ASP.NET application (no classic asp) and it has a main page...
0
by: Alexander Widera | last post by:
hello all, i have a problem ... like I already discussed in the thread "session empty" I have the following problem: I created a completely new web... i added 2 files: sessiontest1.aspx:
3
by: stclaus | last post by:
Hi, I'm currently experiencing a problem using sessions under php 4.4.2. I store variables and objects inside session variables, and all works well under php 5.x, but when I upload those pages to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.