|
Posted by K. A. on 05/05/07 06:27
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 "<p> UserName: ( " . $_SESSION["userid"]. " )</p>";
echo "<p> Password: ( " . $_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!
[Back to original message]
|