Trouble buffering output with Auth
| From: | MrHen | Date: | Thu, 04 Aug 2005 16:02:53 +0000 |
| Subject: | Trouble buffering output with Auth | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-20272@lists.php.net to get a copy of this message | ||
I am using PEAR's Auth package to perform some simple registration on my website and have run into a problem.
My versions:
PHP 4.3.10
Auth 1.2.3
The login function that I provide echos the login form and I want to catch the output so I can stick it wherever I want. I'm using PHP's ob_start() and ob_get_clean() to nab the login form and output in a different location:
*****************************
ob_start();
$auth = new Auth("DB", $params, "loginFunction");
$auth->setSessionname("REGISTRATION");
$auth->start();
$thisStatus = $auth->getStatus();
$valid_login = $auth->checkAuth();
$HTML_login = ob_get_clean();
print $HTML_login;
if ($valid_login) {
print "Good login.<br/>";
print '<a href="">Continue?</a><br/>';
} else {
print "Bad login.<br/>";} ***************************** Once I submit valid login information Auth logs me in and I can see the "Good login" and the "Continue" link. If I click continue I am no longer logged in and I see the "Bad login" notification. If instead of ob_get_clean() I do a ob_get_contents() and never end the output buffer the login works past the first page but it outputs the login form twice. ***************************** //$HTML_login = ob_get_clean(); $HTML_login = ob_get_contents(); print $HTML_login; ***************************** It will output the form once as if I wasn't buffering the output and once again when I print $HTML_login. The login works correctly though, and looking at the HTML it appears that something is adding an additional field to the form: ***************************** <form method="post"> Username: <input type="text" name="username"/> Password: <input type="password" name="password"/> <input type="submit" name="" value="login"/> </form> vs. <form method="post"> <input type="hidden" name="REGISTRATION" value="7db2f2721ec05e74737e60f8b735dea8" /> Username: <input type="text" name="username"/> Password: <input type="password" name="password"/> <input type="submit" name="" value="login"/> </form> ***************************** What happens in the later case is that every link I have on the proceeding pages will have an extra GET tag on the end of it. Such as the "Continue?" link from before: ***************************** <a href="">Continue?</a> vs. <a href="?REGISTRATION=7db2f2721ec05e74737e60f8b735dea8">Continue?</a> ***************************** I have tried everything I could think of, including skimming Auth.php to see if I could find where this extra HTML was being added. For the application I am working on it would be extremely helpful to have the login form HTML stored in an output somehow and the question I have is how should I do this? Output buffering doesn't seem to be working, or at least it isn't with how I have it set up. Is there any way that I can catch that output? Something else I have noticed while testing this is that Auth sometimes uses a cookie to store the login info. I have another page and it always stores the info in a cookie. I haven't been able to figure out what triggers Auth to use a cookie instead of appending a GET tag on the end of all the links, so any help in that would be appreciated too. :) Thank you for your time and help, and if I accidentally sent this to the wrong place I apologize. MrHen. Here is the full code of my test file: <?ini_set('include_path', '/home/mrhencom/pear/PEAR/' . PATH_SEPARATOR .. ini_get('include_path'));?> <? require_once "Auth.php"; ?> <? include_once("phpincludes/constants.php") ?> <? function loginFunction() {
echo '<form method="post" action="">';
echo 'Username: <input type="text" name="username"/><br/>';
echo 'Password: <input type="password" name="password"/><br/>';
echo '<input type="submit" name="" value="login"/>';
echo '</form>';
} //end function
$server = $SERVER;
$username = $USERNAME;
$magic = $PASSWORD;
$database = $DATABASE;
$dsn = "mysql://$username:$magic@$server/$database";
$params = array(
"dsn" => $dsn,
"table" => $TABLE_REG,
"usernamecol" => $TABLE_REG_ID,
"passwordcol" => $TABLE_REG_PASSWORD
);
ob_start();
$auth = new Auth("DB", $params, "loginFunction");
$auth->setSessionname("REGISTRATION");
$auth->start();
$thisStatus = $auth->getStatus();
$valid_login = $auth->checkAuth();
//*
$HTML_login = ob_get_clean();
//*/
/*
$HTML_login = ob_get_contents();
//*/
print $HTML_login;
if ($valid_login) {
print "Good login.<br/>";
print '<a href="">Continue?</a><br/>';
} else {
print "Bad login.<br/>";}