Connecting Tech Pros Worldwide Forums | Help | Site Map

Losing some session values

John
Guest
 
Posts: n/a
#1: Nov 1 '08
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


FutureShock
Guest
 
Posts: n/a
#2: Nov 1 '08

re: Losing some session values


John wrote:
Quote:
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

John
Guest
 
Posts: n/a
#3: Nov 1 '08

re: Losing some session values


On Sat, 01 Nov 2008 07:16:09 -0700, FutureShock <futureshockx@att.net>
wrote:
Quote:
>John wrote:
Quote:
>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
Tim Greer
Guest
 
Posts: n/a
#4: Nov 1 '08

re: Losing some session values


John wrote:
Quote:
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!
John
Guest
 
Posts: n/a
#5: Nov 1 '08

re: Losing some session values


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
Charles Polisher
Guest
 
Posts: n/a
#6: Nov 1 '08

re: Losing some session values


John <67vnue6o@knwfvwrote:
Quote:
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

John
Guest
 
Posts: n/a
#7: Nov 1 '08

re: Losing some session values


On Sat, 01 Nov 2008 19:23:07 +0000, Charles Polisher
<cpolish@nonesuch.comwrote:
Quote:
>John <67vnue6o@knwfvwrote:
Quote:
>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



FutureShock
Guest
 
Posts: n/a
#8: Nov 2 '08

re: Losing some session values


John wrote:
Quote:
On Sat, 01 Nov 2008 19:23:07 +0000, Charles Polisher
<cpolish@nonesuch.comwrote:
>
Quote:
>John <67vnue6o@knwfvwrote:
Quote:
>>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
Geoff Berrow
Guest
 
Posts: n/a
#9: Nov 2 '08

re: Losing some session values


Message-ID: <5u6pg49ctllcqdorpknegjtndm0t4u5gtq@4ax.comfrom John
contained the following:
Quote:
>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
Jerry Stuckle
Guest
 
Posts: n/a
#10: Nov 2 '08

re: Losing some session values


Geoff Berrow wrote:
Quote:
Message-ID: <5u6pg49ctllcqdorpknegjtndm0t4u5gtq@4ax.comfrom John
contained the following:
>
Quote:
>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.
jstucklex@attglobal.net
==================

Jerry Stuckle
Guest
 
Posts: n/a
#11: Nov 2 '08

re: Losing some session values


John wrote:
Quote:
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.
jstucklex@attglobal.net
==================

John
Guest
 
Posts: n/a
#12: Nov 2 '08

re: Losing some session values


On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
Quote:
>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

Jerry Stuckle
Guest
 
Posts: n/a
#13: Nov 2 '08

re: Losing some session values


John wrote:
Quote:
On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>
Quote:
>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.
jstucklex@attglobal.net
==================

John
Guest
 
Posts: n/a
#14: Nov 3 '08

re: Losing some session values


On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<jstucklex@attglobal.netwrote:
Quote:
>John wrote:
Quote:
>On Sat, 01 Nov 2008 13:17:28 +0000, John <67vnue6o@knwfvwrote:
>>
Quote:
>>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


Jerry Stuckle
Guest
 
Posts: n/a
#15: Nov 3 '08

re: Losing some session values


John wrote:
Quote:
On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
<jstucklex@attglobal.netwrote:
>
Quote:
>John wrote:
Quote:
>>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.
jstucklex@attglobal.net
==================

John
Guest
 
Posts: n/a
#16: Nov 3 '08

re: Losing some session values


On Mon, 03 Nov 2008 07:58:13 -0500, Jerry Stuckle
<jstucklex@attglobal.netwrote:
Quote:
>John wrote:
Quote:
>On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
><jstucklex@attglobal.netwrote:
>>
Quote:
>>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:
Quote:
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

Jerry Stuckle
Guest
 
Posts: n/a
#17: Nov 3 '08

re: Losing some session values


John wrote:
Quote:
On Mon, 03 Nov 2008 07:58:13 -0500, Jerry Stuckle
<jstucklex@attglobal.netwrote:
>
Quote:
>John wrote:
Quote:
>>On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
>><jstucklex@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:
>
Quote:
>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.
jstucklex@attglobal.net
==================

Rzzap
Guest
 
Posts: n/a
#18: Nov 3 '08

re: Losing some session values


John wrote:
Quote:
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
John
Guest
 
Posts: n/a
#19: Nov 3 '08

re: Losing some session values


On Mon, 03 Nov 2008 12:58:55 -0500, Jerry Stuckle
<jstucklex@attglobal.netwrote:
Quote:
>John wrote:
Quote:
>On Mon, 03 Nov 2008 07:58:13 -0500, Jerry Stuckle
><jstucklex@attglobal.netwrote:
>>
Quote:
>>John wrote:
>>>On Sun, 02 Nov 2008 11:36:55 -0500, Jerry Stuckle
>>><jstucklex@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:
>>
Quote:
>>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

Closed Thread


Similar PHP bytes