473,396 Members | 1,849 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.

Passing session variables across pages

I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is started,
then display a welcome message with the username. Session variables
are passed across pages fine.

Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).

The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.

Any ideas why?

May 2 '07 #1
22 14850
K. A. schrieb:
I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is started,
then display a welcome message with the username. Session variables
are passed across pages fine.

Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).

The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.

Any ideas why?
I guess session_register causes the problem.
You should read the "Caution"-boxes on http://php.net/session_register.
May 2 '07 #2
On May 2, 11:39 am, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
K. A. schrieb:
I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is started,
then display a welcome message with the username. Session variables
are passed across pages fine.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.
Any ideas why?

I guess session_register causes the problem.
You should read the "Caution"-boxes onhttp://php.net/session_register.- Hide quoted text -

- Show quoted text -
I tried removing session register but this turned out worse as it will
store the session variable in the first place.
I mean, before removing session_register, the value
$_SESSION["userid"] was set to NULL, but without session_register, it
will not even know that there is something called
$_SESSION["userid"] !

Still wondering why it will work on one server but not the other!

May 2 '07 #3
On Wed, 02 May 2007 01:03:55 -0700, K. A. wrote:
On May 2, 11:39 am, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
>K. A. schrieb:
I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is started,
then display a welcome message with the username. Session variables
are passed across pages fine.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.
Any ideas why?

I guess session_register causes the problem.
You should read the "Caution"-boxes onhttp://php.net/session_register.- Hide quoted text -

- Show quoted text -

I tried removing session register but this turned out worse as it will
store the session variable in the first place.
I mean, before removing session_register, the value
$_SESSION["userid"] was set to NULL, but without session_register, it
will not even know that there is something called
$_SESSION["userid"] !
You removed the session_register occurrences, but did you instead store
the variables using $_SESSION["username"]= <whatever var or value you
use>? Can't deduct that from your reply.

Maybe a bit of the relevant code may help shed light on the matter.
Rgds,
Sh.

May 2 '07 #4
K. A. wrote:
On May 2, 11:39 am, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
>K. A. schrieb:
>>I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is started,
then display a welcome message with the username. Session variables
are passed across pages fine.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.
Any ideas why?
I guess session_register causes the problem.
You should read the "Caution"-boxes onhttp://php.net/session_register.- Hide quoted text -

- Show quoted text -

I tried removing session register but this turned out worse as it will
store the session variable in the first place.
I mean, before removing session_register, the value
$_SESSION["userid"] was set to NULL, but without session_register, it
will not even know that there is something called
$_SESSION["userid"] !

Still wondering why it will work on one server but not the other!
Which is how it should be. It's quite simple to see if the value has
been set with

if (isset($_SESSION['userid']) ...

I agree with Mike - the caution is there for a reason! Don't try to mix
and match.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 2 '07 #5
Jerry Stuckle wrote:
K. A. wrote:
>On May 2, 11:39 am, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
>>K. A. schrieb:

I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username,
stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is
started,
then display a welcome message with the username. Session variables
are passed across pages fine.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.
Any ideas why?
I guess session_register causes the problem.
You should read the "Caution"-boxes
onhttp://php.net/session_register.- Hide quoted text -

- Show quoted text -

I tried removing session register but this turned out worse as it will
store the session variable in the first place.
I mean, before removing session_register, the value
$_SESSION["userid"] was set to NULL, but without session_register, it
will not even know that there is something called
$_SESSION["userid"] !

Still wondering why it will work on one server but not the other!

Which is how it should be. It's quite simple to see if the value has
been set with

if (isset($_SESSION['userid']) ...

I agree with Mike - the caution is there for a reason! Don't try to mix
and match.
I tried isset myself and got warning notices in my logs about the key
not existing under PHP5... so instead I use:

if ( array_key_exists( 'userid', $_SESSION ) ) {
// do something
}

Am I ok doing this?
May 2 '07 #6
K. A. wrote:
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
session_register() is old-style register_globals-type code. Remove it.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
You remembered session_start()? You need to call that before trying to
access $_SESSION.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
Now Playing ~ ./vol/music/lisa_germano_-_wood_floors.ogg
May 2 '07 #7
Tyno Gendo wrote:
Jerry Stuckle wrote:
>K. A. wrote:
>>On May 2, 11:39 am, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
K. A. schrieb:

I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username,
stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is
started,
then display a welcome message with the username. Session variables
are passed across pages fine.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.
Any ideas why?
I guess session_register causes the problem.
You should read the "Caution"-boxes
onhttp://php.net/session_register.- Hide quoted text -

- Show quoted text -

I tried removing session register but this turned out worse as it will
store the session variable in the first place.
I mean, before removing session_register, the value
$_SESSION["userid"] was set to NULL, but without session_register, it
will not even know that there is something called
$_SESSION["userid"] !

Still wondering why it will work on one server but not the other!

Which is how it should be. It's quite simple to see if the value has
been set with

if (isset($_SESSION['userid']) ...

I agree with Mike - the caution is there for a reason! Don't try to
mix and match.

I tried isset myself and got warning notices in my logs about the key
not existing under PHP5... so instead I use:

if ( array_key_exists( 'userid', $_SESSION ) ) {
// do something
}

Am I ok doing this?
Yes, but I'm not sure why the isset would give you a warning.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 2 '07 #8
Jerry Stuckle wrote:
Yes, but I'm not sure why the isset would give you a warning.
I think isset($array['key']) issues a *notice* under PHP 5 when the key
doesn't exist in the array. (And returns FALSE.)

I suppose internally PHP finds the key in the array *before* it calls the
isset() function, so the E_NOTICE is raised before isset() is called.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux
May 2 '07 #9
Toby A Inkster wrote:
Jerry Stuckle wrote:
>Yes, but I'm not sure why the isset would give you a warning.

I think isset($array['key']) issues a *notice* under PHP 5 when the key
doesn't exist in the array. (And returns FALSE.)

I suppose internally PHP finds the key in the array *before* it calls the
isset() function, so the E_NOTICE is raised before isset() is called.
Hmm, that sounds dumb. The whole purpose of isset is to see if the
variable (in this case an array element) exists, isn't it?

I just tried the following quick program to see what happened:

<?php
printf("0x%x\n", ini_get('error_reporting'));
$a = array();
if (isset($a['x']))
echo "true\n";
else
echo "false\n";
$a['x'] = 5;
if (isset($a['x']))
echo "true\n";
else
echo "false\n";
?>
Results were:
0x17ff
false
true

E_NOTICE is 0x0008, so it is on. And note I did not get a notice. This
is on PHP 5.2.1.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 2 '07 #10
On May 2, 2:25 pm, Schraalhans Keukenmeester <inva...@invalid.spam>
wrote:
On Wed, 02 May 2007 01:03:55 -0700, K. A. wrote:
On May 2, 11:39 am, Mike Roetgers <miker...@informatik.uni-bremen.de>
wrote:
K. A. schrieb:
I have two servers at work, 'A' for testing and development, and
server 'B' for production.
On server A, I wrote a PHP test code to login users then direct them
to a personalized page. This is done in 3 steps:
Step 1. Normal http login page.
Step 2. A page called login.php that takes the posted username, stores
it as $_SESSION["username"], and registers it
session_register("username"); user is taken to the personalized page
according to his username and things are fine up to here. (this page
is not displayed, only for redirecting purposes).
Step 3. On the personalized page, I check whether session is started,
then display a welcome message with the username. Session variables
are passed across pages fine.
Next, I did exactly the same steps on server B; at step 2 (above) user
is directed to the correct page. But when I get to step 3, the session
seems to lose or set all its variables to NULL (I checked this using
var_dump($_SESSION)).
The codes on server A and B are identical. I copied the php.ini file
from server A to B (just in case there were differences) and restarted
Apache on server B. But still, session variables are lost in Step 3
although the session is still running.
Any ideas why?
I guess session_register causes the problem.
You should read the "Caution"-boxes onhttp://php.net/session_register.-Hide quoted text -
- Show quoted text -
I tried removing session register but this turned out worse as it will
store the session variable in the first place.
I mean, before removing session_register, the value
$_SESSION["userid"] was set to NULL, but without session_register, it
will not even know that there is something called
$_SESSION["userid"] !

You removed the session_register occurrences, but did you instead store
the variables using $_SESSION["username"]= <whatever var or value you
use>? Can't deduct that from your reply.

Maybe a bit of the relevant code may help shed light on the matter.
Rgds,
Sh.- Hide quoted text -

- Show quoted text -
===============================================

Thanks all for your contributions, here is a sample of the codes I
wrote:

1. index.html
UserID:<input type="text" name="userid">
Password: <input type="password" name="password">

2. login.php
// This page does not show up, only for re-direction purposes.
<?php
session_start();
if ($_POST && !empty($_POST['userid']) && !empty($_POST['password']))
{
// set session variable.
$_SESSION["userid"] = $_POST['userid'];
$_SESSION["password"] = $_POST['password'];
}

else
{
exit("<p>No userid or password posted!</p>");
}

if (isset($_SESSION["userid"]) && isset($_SESSION["password"]) )
{
$userid = $_SESSION["userid"];
$passwd = $_SESSION["password"];

$conn = OCILogon($userid,$passwd, "myOracle");

if ( $conn AND $userid == 'abc123' )
header("Location: http://vector/test/testvariables.php");
else
echo "Sorry $userid, you have no access to this Web Site";
}

?>

3. testvariables.php
// User is successfully directed to the right page, page opens up.
<?php
if (session_start())
echo "<p>session started</p>";

echo "<pUserName: ( " . $_SESSION["userid"]. " )</p>";
echo "<pPassword: ( " . $_SESSION["password"]. " )</p>";

if (isset($_SESSION["userid"]) && isset($_SESSION["password"]) )
{
// Connect to Database
$userid = $_SESSION["userid"];
$passwd = $_SESSION["password"];

$conn = OCILogon($userid, $passwd, "myOracle");

if ($conn)
{
echo "<p>User: userid is logged on to database.</p>";
echo "<br><a href=\"loggedout.php\">Logout?</p>";
}

}

else
{
echo "<p><h2>Session variables have not been passed across!</h2></
p>";
}

?>

==>>The resulting page http://vector/test/testvariables.php looks
like:
session started
UserName: ( )
Password: ( )

Session variables have not been passed across!
PS. I'm using PHP version 4.3.10, with Apache 1.3.12 (I think!)

In the error log, it says:
Undefined index: userid in testvariables.php on line 5
Undefined index: password in testvariables.php on line 6

I'm quite new to PHP, please help!

May 5 '07 #11
..oO(K. A.)
>==>>The resulting page http://vector/test/testvariables.php looks
like:
session started
UserName: ( )
Password: ( )

Session variables have not been passed across!
PS. I'm using PHP version 4.3.10, with Apache 1.3.12 (I think!)

In the error log, it says:
Undefined index: userid in testvariables.php on line 5
Undefined index: password in testvariables.php on line 6

I'm quite new to PHP, please help!
How's the session ID stored on the client, in a cookie or appended to
the URLs? If it's not stored in a cookie, it will get lost in step 2
when the script redirects.

You could try this:

if (...) {
header('Location: http://example.com/test/testvariables.php?'.SID);
exit;
} else {
...
}

Micha
May 5 '07 #12
On May 5, 12:18 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(K. A.)
==>>The resulting pagehttp://vector/test/testvariables.phplooks
like:
session started
UserName: ( )
Password: ( )
Session variables have not been passed across!
PS. I'm using PHP version 4.3.10, with Apache 1.3.12 (I think!)
In the error log, it says:
Undefined index: userid in testvariables.php on line 5
Undefined index: password in testvariables.php on line 6
I'm quite new to PHP, please help!

How's the session ID stored on the client, in a cookie or appended to
the URLs? If it's not stored in a cookie, it will get lost in step 2
when the script redirects.

You could try this:

if (...) {
header('Location:http://example.com/test/testvariables.php?'.SID);
exit;

} else {
...
}

Micha
Thanks Micha,
I tried appending but did not work with me, could you please elaborate
more,
How do I use the cookie method? (sorry, I am new to this!).

KA

May 5 '07 #13
On May 5, 12:18 pm, Michael Fesser <neti...@gmx.dewrote:
.oO(K. A.)
==>>The resulting pagehttp://vector/test/testvariables.phplooks
like:
session started
UserName: ( )
Password: ( )
Session variables have not been passed across!
PS. I'm using PHP version 4.3.10, with Apache 1.3.12 (I think!)
In the error log, it says:
Undefined index: userid in testvariables.php on line 5
Undefined index: password in testvariables.php on line 6
I'm quite new to PHP, please help!

How's the session ID stored on the client, in a cookie or appended to
the URLs? If it's not stored in a cookie, it will get lost in step 2
when the script redirects.

You could try this:

if (...) {
header('Location:http://example.com/test/testvariables.php?'.SID);
exit;

} else {
...
}

Micha
OK, I have appendid the session id and it showed in the next page's
URL, then what?
the variables are still lost!

May 5 '07 #14
On May 5, 2:03 pm, "K. A." <ka5...@hotmail.comwrote:
On May 5, 12:18 pm, Michael Fesser <neti...@gmx.dewrote:


.oO(K. A.)
>==>>The resulting pagehttp://vector/test/testvariables.phplooks
>like:
>session started
>UserName: ( )
>Password: ( )
>Session variables have not been passed across!
>PS. I'm using PHP version 4.3.10, with Apache 1.3.12 (I think!)
>In the error log, it says:
>Undefined index: userid in testvariables.php on line 5
>Undefined index: password in testvariables.php on line 6
>I'm quite new to PHP, please help!
How's the session ID stored on the client, in a cookie or appended to
the URLs? If it's not stored in a cookie, it will get lost in step 2
when the script redirects.
You could try this:
if (...) {
header('Location:http://example.com/test/testvariables.php?'.SID);
exit;
} else {
...
}
Micha

OK, I have appendid the session id and it showed in the next page's
URL, then what?
the variables are still lost!- Hide quoted text -

- Show quoted text -
Back again,
I guess I know where the problem is. I found out that session
variables are somewhat lost when I use the "header" function as in:

header('Location: http://example.com/test/testvariables.php);

User is correctly taken to the personalised page using the above line,
but then the session variables get lost!

My question now is: once I found out the userid and I know what page
to take him to, what is the best way to re-direct him to that page
without losing session variables?

May 6 '07 #15
K. A. wrote:
On May 5, 2:03 pm, "K. A." <ka5...@hotmail.comwrote:
>On May 5, 12:18 pm, Michael Fesser <neti...@gmx.dewrote:


>>.oO(K. A.)
==>>The resulting pagehttp://vector/test/testvariables.phplooks
like:
session started
UserName: ( )
Password: ( )
Session variables have not been passed across!
PS. I'm using PHP version 4.3.10, with Apache 1.3.12 (I think!)
In the error log, it says:
Undefined index: userid in testvariables.php on line 5
Undefined index: password in testvariables.php on line 6
I'm quite new to PHP, please help!
How's the session ID stored on the client, in a cookie or appended to
the URLs? If it's not stored in a cookie, it will get lost in step 2
when the script redirects.
You could try this:
if (...) {
header('Location:http://example.com/test/testvariables.php?'.SID);
exit;
} else {
...
}
Micha
OK, I have appendid the session id and it showed in the next page's
URL, then what?
the variables are still lost!- Hide quoted text -

- Show quoted text -

Back again,
I guess I know where the problem is. I found out that session
variables are somewhat lost when I use the "header" function as in:

header('Location: http://example.com/test/testvariables.php);

User is correctly taken to the personalised page using the above line,
but then the session variables get lost!

My question now is: once I found out the userid and I know what page
to take him to, what is the best way to re-direct him to that page
without losing session variables?
Do you have session_start() at the beginning of the new page, also?

If you're set up to use cookies to store the session id, this should
have no effect on session variables.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 6 '07 #16
On May 6, 6:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>
Back again,
I guess I know where the problem is. I found out that session
variables are somewhat lost when I use the "header" function as in:
header('Location:http://example.com/test/testvariables.php);
User is correctly taken to the personalised page using the above line,
but then the session variables get lost!
My question now is: once I found out the userid and I know what page
to take him to, what is the best way to re-direct him to that page
without losing session variables?

Do you have session_start() at the beginning of the new page, also?
Yes, I do have session_start(); first thing in all of my php pages.
If you're set up to use cookies to store the session id, this should
have no effect on session variables.
Sorry, I did not get you!

K.A.

May 7 '07 #17
K. A. wrote:
On May 6, 6:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>>Back again,
I guess I know where the problem is. I found out that session
variables are somewhat lost when I use the "header" function as in:
header('Location:http://example.com/test/testvariables.php);
User is correctly taken to the personalised page using the above line,
but then the session variables get lost!
My question now is: once I found out the userid and I know what page
to take him to, what is the best way to re-direct him to that page
without losing session variables?
Do you have session_start() at the beginning of the new page, also?

Yes, I do have session_start(); first thing in all of my php pages.
>If you're set up to use cookies to store the session id, this should
have no effect on session variables.

Sorry, I did not get you!

K.A.
PHP needs a way to keep track of the id for your session. It can do
this with cookies (most common) or by adding the session id as a query
parameter to your URI.

If you're using cookies (most common), a redirect should not make any
difference. However, if you're not, the session id may get lost.

One other thing - are you redirecting to the same domain, using the same
protocol, etc.?

How about showing us the actual code you're using?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 7 '07 #18
On May 7, 5:49 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
K. A. wrote:
On May 6, 6:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Back again,
I guess I know where the problem is. I found out that session
variables are somewhat lost when I use the "header" function as in:
header('Location:http://example.com/test/testvariables.php);
User is correctly taken to the personalised page using the above line,
but then the session variables get lost!
My question now is: once I found out the userid and I know what page
to take him to, what is the best way to re-direct him to that page
without losing session variables?
Do you have session_start() at the beginning of the new page, also?
Yes, I do have session_start(); first thing in all of my php pages.
If you're set up to use cookies to store the session id, this should
have no effect on session variables.
Sorry, I did not get you!
K.A.

PHP needs a way to keep track of the id for your session. It can do
this with cookies (most common) or by adding the session id as a query
parameter to your URI.

If you're using cookies (most common), a redirect should not make any
difference. However, if you're not, the session id may get lost.

One other thing - are you redirecting to the same domain, using the same
protocol, etc.?

How about showing us the actual code you're using?
The code is displayed above, just scroll up. I found out (from php.net
discussions) that this is a common problem, so it is not just me.
Yes, I'm redirecting to the same domain.

I guess I'm going to try using cookies. Will try that when I get to
work tomorrow.

May 7 '07 #19
K. A. wrote:
On May 7, 5:49 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>K. A. wrote:
>>On May 6, 6:29 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Back again,
I guess I know where the problem is. I found out that session
variables are somewhat lost when I use the "header" function as in:
header('Location:http://example.com/test/testvariables.php);
User is correctly taken to the personalised page using the above line,
but then the session variables get lost!
My question now is: once I found out the userid and I know what page
to take him to, what is the best way to re-direct him to that page
without losing session variables?
Do you have session_start() at the beginning of the new page, also?
Yes, I do have session_start(); first thing in all of my php pages.
If you're set up to use cookies to store the session id, this should
have no effect on session variables.
Sorry, I did not get you!
K.A.
PHP needs a way to keep track of the id for your session. It can do
this with cookies (most common) or by adding the session id as a query
parameter to your URI.

If you're using cookies (most common), a redirect should not make any
difference. However, if you're not, the session id may get lost.

One other thing - are you redirecting to the same domain, using the same
protocol, etc.?

How about showing us the actual code you're using?

The code is displayed above, just scroll up. I found out (from php.net
discussions) that this is a common problem, so it is not just me.
Yes, I'm redirecting to the same domain.

I guess I'm going to try using cookies. Will try that when I get to
work tomorrow.
I see some code posted above - but is this ALL of your code? For
instance, you have:

3. testvariables.php
// User is successfully directed to the right page, page opens up.
<?php
if (session_start())
echo "<p>session started</p>";

echo "<pUserName: ( " . $_SESSION["userid"]. " )</p>";
echo "<pPassword: ( " . $_SESSION["password"]. " )</p>";

Is this ALL of the code? Where are the <head></head><bodytags, for
instance? Do you not have them in there?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 7 '07 #20
I see some code posted above - but is this ALL of your code? For
instance, you have:

3. testvariables.php
// User is successfully directed to the right page, page opens up.
<?php
if (session_start())
echo "<p>session started</p>";

echo "<pUserName: ( " . $_SESSION["userid"]. " )</p>";
echo "<pPassword: ( " . $_SESSION["password"]. " )</p>";

Is this ALL of the code? Where are the <head></head><bodytags, for
instance? Do you not have them in there?
No, I only posted what I thought was neccesary to show.
Yes, I do have the HTML tages, they come after session_start() and
before calling echo "<pUserName: ( " . $_SESSION["userid"]. " )</
p>";

Does this help?

May 8 '07 #21

Have you thought that you are using header() to forward to http://example.com
but are coming from http://www.example.com?

When bizarre things like this happen, I would print out the whole
$_SESSION variables to see what is contained in it.
Just use this code at different points in your scripts:
echo "This is the 'blah' point"
echo "<pre>";
print_r($_SESSION);
echo "</pre>";

I would also remove the header() function and use a manual link to see
if you have made a mistake with the function.

I ALWAYS use a custom session name and the output buffer .. sometimes
I need to refresh the page to see the sessions, does refreshing
produce any results? (stupid question but I have to ask!)

Here is the code I use at the start and end of ALL my sites:

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
session_name("your_custom_session_name,");
session_start();
ob_start();
?>

// html header tags
// site body

<?php
ob_end_flush();
?>

May 8 '07 #22
K. A. wrote:
>I see some code posted above - but is this ALL of your code? For
instance, you have:

3. testvariables.php
// User is successfully directed to the right page, page opens up.
<?php
if (session_start())
echo "<p>session started</p>";

echo "<pUserName: ( " . $_SESSION["userid"]. " )</p>";
echo "<pPassword: ( " . $_SESSION["password"]. " )</p>";

Is this ALL of the code? Where are the <head></head><bodytags, for
instance? Do you not have them in there?
No, I only posted what I thought was neccesary to show.
Yes, I do have the HTML tages, they come after session_start() and
before calling echo "<pUserName: ( " . $_SESSION["userid"]. " )</
p>";

Does this help?
You get a lot better help if you post everything. If the problem were
in "what you thought was necessary to show", chances are you would have
found it by now - or someone else would have.

So no, that doesn't help.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 8 '07 #23

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

Similar topics

8
by: ndsoumah | last post by:
hello guys I'm trying to get access to variables I put in a session variable from another page and it fails... here's the exact situation main file page1.php
4
by: Jason Us | last post by:
Does anyone have experience with passing variables from an ASP page to a JSP page. The way it currently works in passing the SSN in the URL. This cannot be good. I thought that storing a...
4
by: A Web Master | last post by:
I am designing a site for a client where I have a frameset and 3 frames (all in ASP). I am creating session variables in the frameset that need to be accessed in the frames. It seams that in...
1
by: eSapient | last post by:
My objective was to implement a 'Wait' page by using a combination of an asynchronous call and a Session variable to signal the end of the wait. My first page has:...
1
by: Kent Ogletree | last post by:
I have a solution the is composed of 2 projects. The first is the main web application itself and is written in VB.NET. The second is a web service written in C#. The main application launches a...
5
by: manny6677 | last post by:
Trying a simple test of passing $_SESSION variables between two php pages. I don't see any data on the second page and the session id that is printed out is not the same as the first page session id...
5
by: gom | last post by:
I am an amatuer asp.net programmer so I hope this question isn't to dumb. I am having difficulty with my understanding of session state. I have an application that stores some values in the...
1
by: KidQuin | last post by:
I am having problems with session value between pages. Happening in both firefox and IE7. I go between page by links so I know it's not header changes. I use session_start as the first line on the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.