Re: newbie - Auth
| From: | Sylvain Gourvil | Date: | Thu, 04 Aug 2005 12:31:01 +0000 |
| Subject: | Re: newbie - Auth | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20263@lists.php.net to get a copy of this message | ||
mel list_php wrote:
Hi,
sorry for the probably basic problem but I just started looking at pear.
I want to use Auth. I followed the basic example:
// Initialization of database related information
$params = array(
"dsn" => "mysql://$user:$pass@$host/$db_name",
"table" => "auth",
"usernamecol" => "username",
"passwordcol" => "password"
);
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>";
}
// A database is used as storage container in this example
$a = new Auth("DB", $params, "loginFunction" );
// Detection, if user is logged in. Otherwise the login form
// is being displayed.
$a->start();
The dsn is ok, I connect using DB::connect just before and it's working fine. The auth table exists as well, and I have the following require at the beginning:
require_once("PEAR.php");
require_once("DB.php");
require_once("DB/mysql.php");
require_once("Auth/Auth.php");
Using echo "ok", everything seems to work until I call $a->start();
The end of the code is:
if ($a->getAuth()) {
if($_GET[act] == "logout") {
// Log user out
$a->logout();
echo "You have been logged out!<br />\n";
echo "<a href=\"$PHP_SELF?act=login\">Login</a><br />\n";
} else {
// output the content of your site, that is only visible
// for users which have been authenticated successfully.
printf("Welcome user <b>%s</b>!<br />\n", $a->getUsername() );
echo "<a href=\"$PHP_SELF?act=logout\">Logout</a><br />\n";
}
} else {
// not authenticated
echo "<center>You are not authenticated.<br />\n";
}
and it displays nothing, I was hoping at last a "not authenticated"....
So I suppose it is an instantiation problem of some kind, but I have no idea what I have to modify or how to check the $a object.
If somebody could explain what I'm doing wrong?
Thanks,
melanie
_________________________________________________________________
Want to block unwanted pop-ups? Download the free MSN Toolbar now! http://toolbar.msn.co.uk/
It seems to be right !
here's my code if you want it. It could help you but it is the same
[CODE]
$auth = new MyAuth();
$auth->setExpire(7200, 'false');
$auth->setIdle(1200, 'false');
$auth->start();
$status = $auth->getStatus();
if ( $auth->getAuth() )
{
if( isset( $_GET['act'] ) )
{
$act = $_GET['act'];
if($act == "logout")
{
// Log user out
$auth->logout();
$type = 'public';
}else{
$type = 'private';
}
}else{
$type = 'private';
}
}else{
$type = 'public';} [/CODE] and it is working fine. Did you change somme of auth's method or not ? -- --------------------- Sylvain Gourvil Développeur PHP5, PEAR, SMARTY, POSTGRESQL Antiquités en France