Help!? Auth and Redirect!!!
| From: | Jochen Schneider | Date: | Thu, 13 Feb 2003 16:02:29 +0000 |
| Subject: | Help!? Auth and Redirect!!! | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-13231@lists.php.net to get a copy of this message | ||
Hi!
I'm using Pear's Auth classes and I've made some good experiences with it, until now.
Trying to combine a Auth-Session with an Header-Redirect, I'm loosing the session during the Redirection and the called site is asking me for authorization again.
I did some searches and found in the manual(php.net) the function "session_write_close()" to be called before doing a Forward.
But I havent succeeded anyways.
So help me please, cause I dont know how to solve this and I'm getting mad after days of trying and testing... ;-)
Here's some code pieces, for testing!
BTW, It seems to be a problem of CGI-Installations....
Many thx and best regards
Jochen Schneider
First site (1.php):
<?php
require_once('./includes/application_top.php');
require_once(authenticate.php);
$sessarray = $myauth->getAuthData(sessarray);
echo "sessarray: ".$sessarray['mstufid'];
$sessarray2 = array("a"=>"Orange", "b"=>"Banane", "c"=>"Apfel");
$sessarray = array_merge($sessarray, $sessarray2);
$myauth->setAuthData($sessarray);
//for testing
//session_write_close();
//calls after 5 sec. the page 2.php
//Ausgabe an den Browser
$fwdTime = "5";
$fwdURL = "2.php";
echo "
<html xmlns=\"http://www.w3.org/TR/xhtml1/\">
<head>
<title>test</title>
<meta http-equiv=\"refresh\" content=\"$fwdTime; URL=$fwdURL\">
</head>
<body>
</body>
</html>
";
echo "<a href='2.php'>2.php</a>";
?>
The called site (2.php):
<?php
require_once('./includes/application_top.php');
require_once(authenticate.php);
$sessarray = $myauth->getAuthData(sessarray);
echo "sessarray: ".$sessarray['mstufid'];
?>
The login.. (authenticate.php):
Attention, I've did some changes before posting. This should only show the auth-mechanism in common...
<?php
require_once('./includes/application_top.php');
require_once('Auth/Auth.php');
require_once('DB.php');
require_once(dbcon.php); //data for DB-Connection as dsn
// define login form function
function myloginform($username) {
global $PHP_SELF;
echo "<form method=\"post\" action=\"" . $PHP_SELF . "\"><br>";
echo "<input type=\"text\" name=\"username\"><br>";
echo "<input type=\"password\" name=\"password\"><br>";
echo "<input type=\"submit\">";
echo "</form>";
exit();
}
// create auth object
$myauth = new Auth( "DB", $AuthParams, 'myloginform', true);
// start auth session
$myauth->start(); // This also calls session_start()
$username=$myauth->getUsername();
if (!$myauth->getAuth()) {
myloginform();
}
?>