Problems with Auth
| From: | Markus | Date: | Fri, 16 Aug 2002 09:44:18 +0000 |
| Subject: | Problems with Auth | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2128@lists.php.net to get a copy of this message | ||
I have a Problem with the auth file:
I works excellent on the first file. First the user come to the login
screen and fills in the username and the password and the system
confirms them.
But then I have a link to another page. But on the other page a have no
change to geht the information if he is logged in or not.
I think i tried every possibility beside the right one.
Do I have to register the variable $myauth to the session?
It doesn't work either.
On the next page the compiler tells me that i try to:
Call to a member function on a non-object ....
It is clear to me that he don't know the class, but how can I use the
AUTH on more pages without logging in in every single page?
Markus Scheffknecht
File 1:
<?php
require_once "Auth/Auth.php";
session_start();
// set options
$options = array(
'dsn' => 'mysql://test:test@localhost/test',
'table' => 'users',
'usernamecol' => 'username',
'passwordcol' => 'password'
);
// 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>";
}
// create auth object
$myauth = new Auth( "DB", $options, 'myloginform', true);
// start auth session
$myauth->start();
if ($myauth->getAuth()) {
echo "Welcome user ".$myauth->getUsername()."!<br />\n";
echo "<a href=\"test2.php\">Second page</a>";
}
?>
File 2:
<?PHP
require_once "Auth/Auth.php";
session_start();
$myauth->setShowLogin("false");
// start auth session
$myauth->start();
if ($myauth->getAuth ()) {
echo "Welcome user to the 2nd page ".$myauth->getUsername()."! <br>
";
echo "<a href=\"test2.php\">hallo</a>";
}
else{
echo "Not logged in";
}
?>