By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,839 Members | 2,270 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,839 IT Pros & Developers. It's quick & easy.

Losing some session values

P: n/a
Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John

Nov 1 '08 #1
Share this Question
Share on Google+
18 Replies


P: n/a
John wrote:
Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John
And you have gone back with the values you know that work just to make
sure you did not goof up the code after testing the one that does not work?

Maybe it's a typo here but S_SESSION should be $_SESSION.

Shoot us the actual code, sometimes there are small procedural problems
that don't transcribe when writing it to the NG.

Scotty

Nov 1 '08 #2

P: n/a
On Sat, 01 Nov 2008 07:16:09 -0700, FutureShock <fu**********@att.net>
wrote:
>John wrote:
>Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John

And you have gone back with the values you know that work just to make
sure you did not goof up the code after testing the one that does not work?

Maybe it's a typo here but S_SESSION should be $_SESSION.

Shoot us the actual code, sometimes there are small procedural problems
that don't transcribe when writing it to the NG.

Scotty
Thanks Scotty

My mistake in this post I'm afraid. All $_SESSION variables correct.

Here they are cut & pasted -

Page 1 - Set up
$_SESSION['org_details'] = $_POST['ORD_ORG'];

Page 1 use
<h1><?php echo $_SESSION['org_details']; ? OK

Page 2 use
echo $_SESSION['org_details'];
Value is empty

John
Nov 1 '08 #3

P: n/a
John wrote:
Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John
Are you using anything like Smarty templates or some other such thing?
Does debug or verbose output help show anything?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
Nov 1 '08 #4

P: n/a
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
Here's the testing I did -

PAGE 1 CODE

$_SESSION[org_details] = $_POST['ORD_ORG'];
echo "1-$_SESSION[org_details]*<BR>";

$temp = 67;
$_SESSION[org_details1] = $temp;
echo "2-$temp-$_SESSION[org_details1]*<BR>";

$temp = $_POST['ORD_ORG']."1";
$_SESSION[org_details2] = $temp;
echo "3-$temp-$_SESSION[org_details2]*<BR>";

$temp = "adbr";
$_SESSION[org_details3] = $temp;
echo "4-$temp-$_SESSION[org_details3]*<BR>";

PAGE 1 RESULTS

1-Deptford Boys School*
2-67-67*
3-Deptford Boys School1-Deptford Boys School1*
4-adbr-adbr*

PAGE 2 CODE

echo
"--$_SESSION[org_details]-<BR>--$_SESSION[org_details1]-<BR>--$_SESSION[org_details2]-<BR>--$_SESSION[org_details3]";

PAGE 2 RESULTS
---
--67-
--1-
--adbr

(The strings inside the [] don't seem to make a difference)

John
Nov 1 '08 #5

P: n/a
John <67vnue6o@knwfvwrote:
echo
"--$_SESSION[org_details]-<BR>--$_SESSION[org_details1]-<BR>--$_SESSION[org_details2]-<BR>--$_SESSION[org_details3]";

PAGE 2 RESULTS
---
--67-
--1-
--adbr

(The strings inside the [] don't seem to make a difference)
Maybe you intended:
echo "--{$_SESSION['org_details']}--<BR... etc etc?

HTH,

--
Charles

Nov 1 '08 #6

P: n/a
On Sat, 01 Nov 2008 19:23:07 +0000, Charles Polisher
<cp*****@nonesuch.comwrote:
>John <67vnue6o@knwfvwrote:
>echo
"--$_SESSION[org_details]-<BR>--$_SESSION[org_details1]-<BR>--$_SESSION[org_details2]-<BR>--$_SESSION[org_details3]";

PAGE 2 RESULTS
---
--67-
--1-
--adbr

(The strings inside the [] don't seem to make a difference)

Maybe you intended:
echo "--{$_SESSION['org_details']}--<BR... etc etc?

HTH,
Thanks Charles.

I can't see why the others work without the brace though.

I stored the $_POST value in a db so I was able to pull it out again
which defeats the use of the session variable.

There seems to be some conflict between POST and SESSION but I can't
think what I have chabged that could make a difference.

--
John

Nov 1 '08 #7

P: n/a
John wrote:
On Sat, 01 Nov 2008 19:23:07 +0000, Charles Polisher
<cp*****@nonesuch.comwrote:
>John <67vnue6o@knwfvwrote:
>>echo
"--$_SESSION[org_details]-<BR>--$_SESSION[org_details1]-<BR>--$_SESSION[org_details2]-<BR>--$_SESSION[org_details3]";

PAGE 2 RESULTS
---
--67-
--1-
--adbr

(The strings inside the [] don't seem to make a difference)
Maybe you intended:
echo "--{$_SESSION['org_details']}--<BR... etc etc?

HTH,

Thanks Charles.

I can't see why the others work without the brace though.

I stored the $_POST value in a db so I was able to pull it out again
which defeats the use of the session variable.

There seems to be some conflict between POST and SESSION but I can't
think what I have chabged that could make a difference.
All i can think of doing now to verify your values is output all your
session values.

print_r($_SESSION);

on both pages and see what comes out for sure.

Also you may want to print_r($_POST) on page one to verify your values
there too.

Always remember 'junk in, junk out'

Scotty
Nov 2 '08 #8

P: n/a
Message-ID: <5u********************************@4ax.comfrom John
contained the following:
>Here's the testing I did -
That's still not the whole code, we can't see the form that produces the
$_POST variable. My guess is that you are reloading the page somehow
without posting the form which is destroying the session variable.

You will be better off using concatenation with session variables to
avoid possible problems with mathematical operators (eg - and * )

echo
'--'.$_SESSION['org_details'].'-<BR>--'.$_SESSION['org_details1'].'-<BR>--'.$_SESSION['org_details2'].'-<BR>--.'$_SESSION['org_details3'];

Reduce it down to the smallest possible snippets of code that produce
the problem. If the solution is not obvious, post the code.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011
http://slipperyhill.co.uk - http://4theweb.co.uk
Nov 2 '08 #9

P: n/a
Geoff Berrow wrote:
Message-ID: <5u********************************@4ax.comfrom John
contained the following:
>Here's the testing I did -

That's still not the whole code, we can't see the form that produces the
$_POST variable. My guess is that you are reloading the page somehow
without posting the form which is destroying the session variable.

You will be better off using concatenation with session variables to
avoid possible problems with mathematical operators (eg - and * )

echo
'--'.$_SESSION['org_details'].'-<BR>--'.$_SESSION['org_details1'].'-<BR>--'.$_SESSION['org_details2'].'-<BR>--.'$_SESSION['org_details3'];

Reduce it down to the smallest possible snippets of code that produce
the problem. If the solution is not obvious, post the code.
There is no need to use concatenation - braces within double-quoted
strings work quite well. It's only a matter of style. But he also
needs single quotes around the array names;

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 2 '08 #10

P: n/a
John wrote:
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
Here's the testing I did -

PAGE 1 CODE

$_SESSION[org_details] = $_POST['ORD_ORG'];
echo "1-$_SESSION[org_details]*<BR>";

$temp = 67;
$_SESSION[org_details1] = $temp;
echo "2-$temp-$_SESSION[org_details1]*<BR>";

$temp = $_POST['ORD_ORG']."1";
$_SESSION[org_details2] = $temp;
echo "3-$temp-$_SESSION[org_details2]*<BR>";

$temp = "adbr";
$_SESSION[org_details3] = $temp;
echo "4-$temp-$_SESSION[org_details3]*<BR>";

PAGE 1 RESULTS

1-Deptford Boys School*
2-67-67*
3-Deptford Boys School1-Deptford Boys School1*
4-adbr-adbr*

PAGE 2 CODE

echo
"--$_SESSION[org_details]-<BR>--$_SESSION[org_details1]-<BR>--$_SESSION[org_details2]-<BR>--$_SESSION[org_details3]";

PAGE 2 RESULTS
---
--67-
--1-
--adbr

(The strings inside the [] don't seem to make a difference)

John
You need braces around your array elements when using them in a
double-quoted string, and single quotes around the array indexes.

The correct way to do it would be:

echo
"--{$_SESSION['org_details']}-<BR>--{$_SESSION['org_details1']}-<BR>--{$_SESSION['org_details2']}-<BR>--{$_SESSION['org_details3']}";

Additionally, as NN indicated, ensure you have session_start() at the
beginning of EVERY page which uses session data.

And ensure you have these in the php.ini file on your development system:

display_errors=on
error_reporting=E_ALL

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 2 '08 #11

P: n/a
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John
OK found it. Sorry for the wild goose chase but I do appreciate your
help.

Problem was I was using a header to redirect without an exit and the
code was re-executing which meant that some $_POST variables were not
set the second time around.

I now realise I've used headers before without an exit, can I assume
the whole of the code is always run again or this inconsistent?

--
John

Nov 2 '08 #12

P: n/a
John wrote:
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John

OK found it. Sorry for the wild goose chase but I do appreciate your
help.

Problem was I was using a header to redirect without an exit and the
code was re-executing which meant that some $_POST variables were not
set the second time around.

I now realise I've used headers before without an exit, can I assume
the whole of the code is always run again or this inconsistent?
Maybe, maybe not. header() is just a function call. Execution
continues after the call. But in the case of a redirect, the execution
will continue only until the next request comes in from that browser -
after which the code will be terminated (by default). Depending on
system load, the amount of code left, link speed, browser response time,
the phase of the moon and whether you hold your left foot with your
right hand in the correct position or not, code may or may not complete.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 2 '08 #13

P: n/a
On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>John wrote:
>On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>>Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John

OK found it. Sorry for the wild goose chase but I do appreciate your
help.

Problem was I was using a header to redirect without an exit and the
code was re-executing which meant that some $_POST variables were not
set the second time around.

I now realise I've used headers before without an exit, can I assume
the whole of the code is always run again or this inconsistent?

Maybe, maybe not. header() is just a function call. Execution
continues after the call. But in the case of a redirect, the execution
will continue only until the next request comes in from that browser -
after which the code will be terminated (by default). Depending on
system load, the amount of code left, link speed, browser response time,
the phase of the moon and whether you hold your left foot with your
right hand in the correct position or not, code may or may not complete.
So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page. A redirect is used and the next page
starts processing, perhaps retrieving data from a large database and
carrying out some calculations.

What you are saying is the user will see his page presented back to
him first, in this case. Now while processing is happening on the
second page, it is not hard to image a communications link seizing up
such that the new second page is held up.

To the user it looks like nothing has happened but in fact the fist
page has been processed again, and items updated possibly.

Is that correct?

--
John
Nov 3 '08 #14

P: n/a
John wrote:
On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>John wrote:
>>On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:

Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Other session variables seem ok also.

Confused of Bromley

Thanks John
OK found it. Sorry for the wild goose chase but I do appreciate your
help.

Problem was I was using a header to redirect without an exit and the
code was re-executing which meant that some $_POST variables were not
set the second time around.

I now realise I've used headers before without an exit, can I assume
the whole of the code is always run again or this inconsistent?
Maybe, maybe not. header() is just a function call. Execution
continues after the call. But in the case of a redirect, the execution
will continue only until the next request comes in from that browser -
after which the code will be terminated (by default). Depending on
system load, the amount of code left, link speed, browser response time,
the phase of the moon and whether you hold your left foot with your
right hand in the correct position or not, code may or may not complete.

So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page. A redirect is used and the next page
starts processing, perhaps retrieving data from a large database and
carrying out some calculations.

What you are saying is the user will see his page presented back to
him first, in this case. Now while processing is happening on the
second page, it is not hard to image a communications link seizing up
such that the new second page is held up.

To the user it looks like nothing has happened but in fact the fist
page has been processed again, and items updated possibly.

Is that correct?
That's not at all what I said. Please read it again. There is no way
to display a second page without a request from the client.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 3 '08 #15

P: n/a
On Mon, 03 Nov 2008 07:58:13 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>John wrote:
>On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>>John wrote:
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:

Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).
>
I have done some tests.
>
$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;
>
Passes ok and has value 67 on the next page
>
>
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;
>
Passes ok and has value abc on the next page
>
>
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;
>
No value on next page
>
>
Other session variables seem ok also.
>
Confused of Bromley
>
Thanks John
OK found it. Sorry for the wild goose chase but I do appreciate your
help.

Problem was I was using a header to redirect without an exit and the
code was re-executing which meant that some $_POST variables were not
set the second time around.

I now realise I've used headers before without an exit, can I assume
the whole of the code is always run again or this inconsistent?

Maybe, maybe not. header() is just a function call. Execution
continues after the call. But in the case of a redirect, the execution
will continue only until the next request comes in from that browser -
after which the code will be terminated (by default). Depending on
system load, the amount of code left, link speed, browser response time,
the phase of the moon and whether you hold your left foot with your
right hand in the correct position or not, code may or may not complete.

So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page. A redirect is used and the next page
starts processing, perhaps retrieving data from a large database and
carrying out some calculations.

What you are saying is the user will see his page presented back to
him first, in this case. Now while processing is happening on the
second page, it is not hard to image a communications link seizing up
such that the new second page is held up.

To the user it looks like nothing has happened but in fact the fist
page has been processed again, and items updated possibly.

Is that correct?

That's not at all what I said. Please read it again. There is no way
to display a second page without a request from the client.
Sorry Jerry I don't understand in the case.

In my scenario the client did request the second page:
So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page.
I may have not been clear with this. The redirect is at the top of the
page and the page calls itself. That is why it would continue
processing the second around.

--
John

Nov 3 '08 #16

P: n/a
John wrote:
On Mon, 03 Nov 2008 07:58:13 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>John wrote:
>>On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:

John wrote:
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>
>Something strange has just started to happen as I have been developing
>a db application on a site. Suddenly a session variable has stopped
>working as I pass it from 1 page to another (I am sure it was OK a few
>days ago).
>>
>I have done some tests.
>>
>$temp = 67;
>echo $temp; gives 67 on this page
>S_SESSION['org'] = $temp;
>>
>Passes ok and has value 67 on the next page
>>
>>
>$temp = "abc"
>echo $temp gives "abc" on this page
>S_SESSION['org'] = $temp;
>>
>Passes ok and has value abc on the next page
>>
>>
>$temp = $_POST['CUST_ORG']
>echo $temp; gives "org 1" on this page
>S_SESSION['org'] = $temp;
>>
>No value on next page
>>
>>
>Other session variables seem ok also.
>>
>Confused of Bromley
>>
>Thanks John
OK found it. Sorry for the wild goose chase but I do appreciate your
help.
>
Problem was I was using a header to redirect without an exit and the
code was re-executing which meant that some $_POST variables were not
set the second time around.
>
I now realise I've used headers before without an exit, can I assume
the whole of the code is always run again or this inconsistent?
>
Maybe, maybe not. header() is just a function call. Execution
continues after the call. But in the case of a redirect, the execution
will continue only until the next request comes in from that browser -
after which the code will be terminated (by default). Depending on
system load, the amount of code left, link speed, browser response time,
the phase of the moon and whether you hold your left foot with your
right hand in the correct position or not, code may or may not complete.
So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page. A redirect is used and the next page
starts processing, perhaps retrieving data from a large database and
carrying out some calculations.

What you are saying is the user will see his page presented back to
him first, in this case. Now while processing is happening on the
second page, it is not hard to image a communications link seizing up
such that the new second page is held up.

To the user it looks like nothing has happened but in fact the fist
page has been processed again, and items updated possibly.

Is that correct?
That's not at all what I said. Please read it again. There is no way
to display a second page without a request from the client.

Sorry Jerry I don't understand in the case.

In my scenario the client did request the second page:
>So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page.

I may have not been clear with this. The redirect is at the top of the
page and the page calls itself. That is why it would continue
processing the second around.
You can't send two pages to the same client. If you output ANYTHING
(even white space) from the first page, the header() call will fail.

If, instead, you use the header('Location: ...') call to redirect, the
client will request the new page. At that time, the connection for the
first page will be closed. Any time after that, processing of the first
page may be terminated by PHP. There is no guarantee whether or not the
code on the first page will complete or not. This is typically when the
first page attempts to send output to the client, but that's not
guaranteed, AFAIK.

The bottom line is - if you want to redirect AND do processing - do ALL
of your processing before the header() call. Don't count on processing
to continue after the header('Location: ...') call.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 3 '08 #17

P: n/a
John wrote:
Something strange has just started to happen as I have been developing
a db application on a site. Suddenly a session variable has stopped
working as I pass it from 1 page to another (I am sure it was OK a few
days ago).

I have done some tests.

$temp = 67;
echo $temp; gives 67 on this page
S_SESSION['org'] = $temp;

Passes ok and has value 67 on the next page
$temp = "abc"
echo $temp gives "abc" on this page
S_SESSION['org'] = $temp;

Passes ok and has value abc on the next page
$temp = $_POST['CUST_ORG']
echo $temp; gives "org 1" on this page
S_SESSION['org'] = $temp;

No value on next page
Given lack of time I'm not browsing the total thread, but if:
- register_globals enabled?
- (possibly global) variable named $org?
Then:
- Try to disable register_globals and see if the problem continues.
- If unable to do that, or this doesn't fix it, try to use a different name.

If things still get weird, I normally employ a "bogus" singleton object
around my $_SESSION array, use that (and solely that) to set my
$_SESSION values, in which case I can monitor & log alteration with the
__get() & __set() methods.

My server doesn't carry alt.* groups, removed
--
Grtz,

Rik
Nov 3 '08 #18

P: n/a
On Mon, 03 Nov 2008 12:58:55 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>John wrote:
>On Mon, 03 Nov 2008 07:58:13 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:
>>John wrote:
On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<js*******@attglobal.netwrote:

John wrote:
>On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>>
>>Something strange has just started to happen as I have been developing
>>a db application on a site. Suddenly a session variable has stopped
>>working as I pass it from 1 page to another (I am sure it was OK a few
>>days ago).
>>>
>>I have done some tests.
>>>
>>$temp = 67;
>>echo $temp; gives 67 on this page
>>S_SESSION['org'] = $temp;
>>>
>>Passes ok and has value 67 on the next page
>>>
>>>
>>$temp = "abc"
>>echo $temp gives "abc" on this page
>>S_SESSION['org'] = $temp;
>>>
>>Passes ok and has value abc on the next page
>>>
>>>
>>$temp = $_POST['CUST_ORG']
>>echo $temp; gives "org 1" on this page
>>S_SESSION['org'] = $temp;
>>>
>>No value on next page
>>>
>>>
>>Other session variables seem ok also.
>>>
>>Confused of Bromley
>>>
>>Thanks John
>OK found it. Sorry for the wild goose chase but I do appreciate your
>help.
>>
>Problem was I was using a header to redirect without an exit and the
>code was re-executing which meant that some $_POST variables were not
>set the second time around.
>>
>I now realise I've used headers before without an exit, can I assume
>the whole of the code is always run again or this inconsistent?
>>
Maybe, maybe not. header() is just a function call. Execution
continues after the call. But in the case of a redirect, the execution
will continue only until the next request comes in from that browser -
after which the code will be terminated (by default). Depending on
system load, the amount of code left, link speed, browser response time,
the phase of the moon and whether you hold your left foot with your
right hand in the correct position or not, code may or may not complete.
So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page. A redirect is used and the next page
starts processing, perhaps retrieving data from a large database and
carrying out some calculations.

What you are saying is the user will see his page presented back to
him first, in this case. Now while processing is happening on the
second page, it is not hard to image a communications link seizing up
such that the new second page is held up.

To the user it looks like nothing has happened but in fact the fist
page has been processed again, and items updated possibly.

Is that correct?

That's not at all what I said. Please read it again. There is no way
to display a second page without a request from the client.

Sorry Jerry I don't understand in the case.

In my scenario the client did request the second page:
>>So I can envisage a scenario whereby a user clicks a submit button
expecting to go to another page.

I may have not been clear with this. The redirect is at the top of the
page and the page calls itself. That is why it would continue
processing the second around.

You can't send two pages to the same client. If you output ANYTHING
(even white space) from the first page, the header() call will fail.

If, instead, you use the header('Location: ...') call to redirect, the
client will request the new page. At that time, the connection for the
first page will be closed. Any time after that, processing of the first
page may be terminated by PHP. There is no guarantee whether or not the
code on the first page will complete or not. This is typically when the
first page attempts to send output to the client, but that's not
guaranteed, AFAIK.

The bottom line is - if you want to redirect AND do processing - do ALL
of your processing before the header() call. Don't count on processing
to continue after the header('Location: ...') call.
Thanks Jerry

I think its clear now.

--
John

Nov 3 '08 #19

This discussion thread is closed

Replies have been disabled for this discussion.