|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-12-21 03:12 UTC] kannan at tmsassociates dot com
I have 2 scripts: a script to login a user and set a session variable. After checking session_is_registered() I redirect to a url using header(). The target script checks for the session variable and is not able to find it.
If I use href to go to the target page, the session variable is found.
I have reviewed the bugs database, and the solutions reported for similar cases do not work for me. The following are portion of the code used:
I tested the code on a Linux server and it works perfectly.
Thank you.
Kannan
Environment: Windows 2000, IE 5.5, Linux 4.0.6
Login.php>>
$db = db_connect();
$result = mysql_query($query, $db);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$row = mysql_fetch_array($result);
$suser = $user;
session_register("suser");
}
}
if (session_is_registered("suser"))
{
if ($redirect<>"")
header("location: $redirect");
// redirect is instantiated with 'members_only.php'
else {
echo "You are logged in as: $suser <br>";
echo "suser: $suser<br>";
echo "<a href=\"members_only.php\">Members Only</a><br>";
echo "<a href=\"logout.php\">Log out</a><br>"; // ======= redirect to URL ====
}
}
.....
members_only.php>>
<?
session_start();
// check session variable
echo "Members_only<br>";
echo "$suser<br>";
if (session_is_registered("suser"))
{
echo "Members Only Page<br>";
echo "<p>You are logged in as $suser.</p>";
echo "<p>Members only content goes here</p>";
echo "<a href=\"login.php\">Back to main page</a>";
echo "<a href=\"logout.php\">Logout</a>";
}
else
{ $redirect = "members_only.php";
header("location: login.php?redirect=$redirect");
}
?>
php.ini>>
[Session]
session.save_handler = files
session.save_path = C:\temp
session.use_cookies = 1
session.name = FOO
session.auto_start = 1
session.cookie_lifetime = 60
session.cookie_path = c:\temp
session.cookie_domain =
session.serialize_handler = php
session.gc_probability = 1
session.gc_maxlifetime = 1440
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = private
session.cache_expire = 180
session.use_trans_sid = 1
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 05:00:01 2025 UTC |
I have experienced a similar problem with Kannan but not due to session.auto_start. In my php.ini session.auto_start is set to 0. I use the following scripts. When run, either with PHP Version 4.0.6, or with Version 4.1.1 and IIS under NT 4.0, the second script - test_login.php - starts a new session and variable $username is unset. When run with PHP 4.0.1 and Apache under Unix they work just fine. // ------ login.php ------ <?php session_start(); session_register("username"); $username = "justme"; Header("Location: ./test_login.php"); ?> // ------ test_login.php ------ <?php session_start(); if ( isset ($username) ) echo $username; else echo "Not authenticated!"; ?> // ----------------------- According to Chris 'This is actually not a bug at all but rather behavior of HTTP'. If this is the case then how comes that I don't have this problem when I use PHP Version 4.0.1 with Apache?Hi I've also had a similar problem of session variables not being passed following a call to header(). I am running PHP 4.0.15 on an XP m/c. The following worked for me, by placing a session_write_close() before the call to header, followed by and exit(): session_write_close(); header("Location: $strPage"); exit(); I hope this will be of use to some. Andrew WhaleI would have liked a simple header redirect as well, but unfortunately the other suggestions didn't solve the issue. However, setting a javascript redirect seemed to do the trick. I'm using Win2k professional, IIS 5.0, PHP Version 4.3.4 This will work on IE browsers. Just modify the javascript for netscape compatibility. <? //...perform login check, produce $errStr if fails if($errStr){ header("Location: login.php?err=".$errStr); }else{ print '<html> <body onload=eval("window.location.href=\'http://blahblahblah/default.php\';");></body> </html>'; } ?>I'm working on PHP 4.2.3 with Apache 1.3.9 and I've got the problem mentioned above. After logging in I do the simple session_start() $_SESSION['user'] = $_POST['login'] and as for that everythings fine. But when changing from test.php, where above code is stored, into another page klient.php during the same session the variable appears to be empty! In short, although the variable is being registered fine it's not visible in other scripts, what is an obvious denial of an idea of session variables. Can anyone help? I've been fighting this one for over three days in many ways but nothing seems to have an effect. test.php: session_start(); header("Cache-control: private"); ob_end_flush(); session_register("log"); session_register("pas"); $log = $_POST["login"]; $pas = $_POST["pass"]; klient.php: session_start(); header("Cache-control: private"); ob_end_flush(); $im = $log; $naz = $pas; echo "->".$im; Big thanks in advance