Create a page called yz.php
Copy Code code as follows:
<?php
Require_once (' auth.php ');
function Show_login_form () {
Echo ' <form method= "post" action= "yz.php" >
<p>username:<input type= "text" name= "username" ></p>
<p>password:<input type= "password" name= "password" ></p>
<p><input type= "Submit" value= "submitted" ></p>
' ;
}
$options =array (' DSN ' => ' Mysql://root:1@localhost/zs ',
' Table ' => ' users ',
' Usernamecol ' => ' user_name ',
' Passwordcol ' => ' user_passwd ',
' Crypttype ' => ',
' Db_fields ' => ' *,
);
$auth =new auth (' DB ', $options, ' show_login_form ');
?>
<body>
<?php
$auth->start ();
if ($auth->checkauth ()) {
echo "OK";
echo "<br>";
echo "<a href= ' yzh.php ' >add</a>";
}else {
echo "Error";
}
$auth->setsessionname ($auth->getauthdata (' user_name '));
?>
</body>
The page yzh.php after the logon session
Copy Code code as follows:
<?php
function back () {
Echo ' <a href= ' yz.php ' >back</a> ';
}
Require_once (' auth.php ');
$auth =new auth (' DB ', $option, ' back ');
$auth->start ();
if ($auth->checkauth ())
{
echo "This is a session page,welcome";
echo "{$auth->getusername ()}";
}
?>