Re: [PHPLIB] login form on every page From: Patrick _ (phplib <email protected>)
Date: 11/11/99

Hi,

Attached you will find a snippet that I use to display a login link only if
the user has not been logged in. You can easily use this in every page by
including it. Assuming the code is correct of course. I am pretty new to
phplib.

<?php
if ($auth->auth["uid"] == "nobody"):
?>
<A HREF="<?php $sess->purl("$PHP_SELF?again=yes") ?>">Login</A>
<?php endif ?>

<?php
// Put the condition in for the logout link. If you are not
// logged in you should not log out otherwise Bad Things will happen
if ($auth->auth["perm"] <> ""):
?>
<A HREF="<?php $sess->purl("logout.php3") ?>">Logout</A>
<?php endif ?>

And here is the logout.php3 that I put together. It automagically logs out
(only if logged in) and then redirects the user back to the referring url.

<?php
//
page_open(array("sess" => "Example_Session", "auth" =>
"Example_Default_Auth", "perm" => "Example_Perm", "user" =>
"Example_User"));

// Now make sure only people get here that are actually logged in
// if not than redirect them to the main

$user->register("u");
$sess->register("s");

//

if ($auth->auth["uid"] == "nobody")
{
$stop_at = strcspn($HTTP_REFERER,"?");
$ref_url = substr($HTTP_REFERER,0,$stop_at);
Header("Location:". $sess->url($ref_url));
exit;
}

// Now log the user out

$auth->logout();
page_close();

// and redirect back to where it came from

Header("Location:". $sess->url($ref_url));
exit;
?>

Hope this helps.

Regards,
-Patrick

>From: Donncha O Caoimh <donncha.ocaoimh <email protected>>
>To: David Tiselius <david.t <email protected>>
>CC: phplib <email protected>
>Subject: Re: [PHPLIB] login form on every page
>Date: Thu, 11 Nov 1999 12:20:23 +0000
>
>I think I fixed it: default_auth is your friend!
>Thanks to David's example code I was able to construct a sane login
>procedure :)
>
>Donncha.
>
>David Tiselius wrote:
> >
> > Donncha O Caoimh wrote:
> > >
> > > Has anyone tried to put a login form on each page of a web site using
> > > phplib?
> > > At the moment I'm trying to let users login no matter where they are
>on
> > > the web site.
> > > I put a page_open command in prepend.inc and defined my own
>session,auth
>-
>PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
>To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
>the body, not the subject, of your message.

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
-
PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>.
To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in
the body, not the subject, of your message.