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

Passing session variables across pages

P: n/a
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
Share this Question
Share on Google+
22 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
..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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.