RE: [PEAR] Auth and header("Location:...") issues
| From: | Joseph Blythe | Date: | Fri, 18 Jul 2003 06:54:49 +0000 |
| Subject: | RE: [PEAR] Auth and header("Location:...") issues | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-6661@lists.php.net to get a copy of this message | ||
Hi there Wade,
When I use Auth I just have a dummy function login() in auth.include.php and
then have a login form page with the correct input mappings to "username"
and "password" example below:
auth.include.php----->
include "setup.include.php"; // contains database setup
function login() {
//dummy function
}
// set options
$auth_options = array(
'table' => 'customers',
'usernamecol' => 'username',
'passwordcol' => 'password',
'dsn' => $dsn
);
<----end
whatever.php----->
include_once('auth.include.php');
// create auth object
$myauth = new Auth('DB', $auth options, "login");
$myauth->start();
if ($myauth->getAuth()) {
// authenicated page content
} else {
// login form page
}
Note I usually use a template class so I just change which template is
displayed and which vars are sent to it not sure if this the best way either
but works quite well.
Hope this helps,
Regards,
Joseph
> -----Original Message-----
> From: wade [mailto:wdawson61@yahoo.com]
> Sent: Friday, 18 July 2003 3:46 PM
> To: pear-general@lists.php.net
> Subject: [PEAR] Auth and header("Location:...") issues
>
>
> Hi All:
> I'm trying to use the Auth package and have a few questions:
>
> PHP version 4.3.1
> Apache version 1.3.27
> Auth version 1.2.0
>
>
> 1) I'm trying to use the example in the top of the Auth.php
> file and place the
> creation of the Auth object and the $myauth->start() code in
> a file that gets
> included in all the pages I want to secure. I have a little
> example script
> here that just secures the phpinfo() function as follows: (more below)
>
> >>> begin phpinfo_test.php:
>
> <?
> include "auth_test.php";
> if ($myauth->getAuth()) {
> phpinfo();
> }
> else {
> header("Location: ²«¨
> ”$)ABõ÷[¢²ŠÒhttp://www.ohthepainwilliam.com");
> }
> ?>
> >>> end phpinfo_test.php:
>
> >>> begin auth_test.php
> <?
> require_once("Auth/Auth.php");
>
> function loginFunction()
> {
> /**
> * Change the HTML output so that it fits to your
> * application.
> */
> echo "<form method=\"post\" action=\"" .
> $_SERVER['PHP_SELF'] . "\">";
> echo "<input type=\"text\" name=\"username\">";
> echo "<input type=\"password\" name=\"password\">";
> echo "<input type=\"submit\">";
> echo "</form>";
> }
>
>
> // define dsn
> $dsn = "mysql://root:@localhost/customer";
>
> // set options
> $options = array(
> 'table' => 'customers',
> 'usernamecol' => 'userlogin',
> 'passwordcol' => 'password',
> 'dsn' => $dsn
> );
>
> // create auth object
> $myauth = new Auth('DB', $options,"loginFunction");
> $myauth->start();
> ?>
>
>
> How do I load a different page upon an authentication failure?
>
> 2) Is this the way this is intended to be used???
>
> Thanks,
> Wade.
>
>
>
>
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month!
> http://sbc.yahoo.com
>
> --
> PEAR General Mailing List (http://pear.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php