473,804 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with session variables

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

<FORM action="index15 dq.php" method="post" name="stegscf_p wd_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 2278
Rik
Garry Jones wrote:
This is a excerpt from the code where I collect data with a form.

<FORM action="index15 dq.php" method="post" name="stegscf_p wd_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($_SESSI ON); 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.comskr ev i meddelandet
news:a0******** *************** ****@news2.tude lft.nl...
Yes. print_r($_SESSI ON); 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.sessio n-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.p hp on line 34

Warning: session_start() [function.sessio n-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.p hp 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.comskr ev i meddelandet
news:76******** *************** ****@news2.tude lft.nl...
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($_SESSI ON);
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="index15 dt.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
8327
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 script that is being called. I have read the online manual, and here is an example from it that doesnt work for me, it illustrates very well my problem. File 1, index.php <?php // index.php
13
23341
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 The problem I am having is that each time I reload the same PHP page, I get
1
4008
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 and no load balancer installed. The problem is on the checking of the session timeout function. This function will check if the session variable's value is missing. If it is missing, it will direct to time out page.
3
2831
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 Session("UserType") = "Sales". Then based on the Session("UserType") I use response.redirect to take the user to a specific page. The logic and response.redirect works fine on a Win2k server but when I move the page to a server running Win2003 the...
7
2317
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!!! Our development server started life as an NT4 machine and has been simply upgraded from one operating system to the next, it is now a cross, NT4 Server, Win2000 Server, Win2003 server. All development sites work fine and under heavy stress. ...
5
4481
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 other functions. All these information I will keep by Session = "2" Session = "Student"
6
3262
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 query-string flag is used to indicate to the page whether it should instantiate a new instance of the object or access an existing instance from the calling page. On the both pages I have a property of the page which is an instance of this custom...
8
3359
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 (i.e. kinda SDI main window) that contains an IFrame. 2. I load different ASPX pages (that belong to the same ASP.NET project) in
0
1453
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
2862
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 my hosting (tiscali italia business) the whole site and session variables seem to work at the beginning, but after a variable number of request (sometimes the second, sometimes the fifteenth page requested) all the site get stuck, every request...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10356
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10103
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9179
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.