Scusa non è che non sei chiaro ma sono io che di php non capisco niente...
Codice PHP:
<?PHP
include ("functions.php");
function index($user) {
global $db;
if (is_logged_in($user)) {
$cookie_read = explode("|", base64_decode($user));
$userid = $cookie_read[0];
$username = $cookie_read[1];
$password = $cookie_read[2];
$lastlogin_date = $cookie_read[4];
$lastlogin_time = $cookie_read[5];
echo ""._WELCOME." <b>$username</b>, "._LAST_LOGIN." "._ON." $lastlogin_date alle $lastlogin_time - <a href=users.php?cat=Logout>"._LOGOUT."</a>";
echo "<br><br><br><br>";
}else{
login_form();
}
}
################################################################################
#------------------------------------------------------------------------------#
# login
#------------------------------------------------------------------------------#
################################################################################
function login_form(){
global $username,$user_err,$pass_err,$error_msg;
echo "<center><font class=\"title\">"._PLEASE_ENTER_YOUR_USER."</font></center>\n";
echo "
<center>
<form method=\"POST\" action=\"users.php\" name=\"loginform\">
<table border=\"0\" cellspacing=\"2\" cellpadding=\"4\">
<tr>
<td bgcolor=\"#E2E2E2\">"._USERNAME." : </td>
<td bgcolor=\"#E2E2E2\"><input type=\"text\" name=\"username\" value=\"$username\" size=\"11\"> $user_err</td>
</tr>
<tr>
<td bgcolor=\"#E2E2E2\">"._PASSWORD." : </td>
<td bgcolor=\"#E2E2E2\"><input type=\"password\" name=\"password\" size=\"11\"> $pass_err</td>
</tr>
<tr>
<td colspan=2>"._REMEBER_ME." <input type=\"checkbox\" name=\"remember\" value=\"ON\"></td>
</tr>
<tr>
<td> </td>
<td> <input type=\"hidden\" name=\"cat\" value=\"do_login\">
<input type=\"submit\" value=\""._LOGIN."\"></p>
</td>
</tr>
</table> $error_msg
</form><a href=\"index.php\">"._HOME."</a> - <a href=\"users.php?cat=Register\">"._REGISTER."</a> - <a href=\"users.php?cat=Forgot_pwd\">"._FORGOT_PASSWORD."</a><br><br>";
}
function Login(){
login_form();
}
function do_login(){
Global $db,$username,$password,$prefix, $remember,$user_err,$pass_err,$error_msg,$validate;
if((!$username) || (!$password)){
$reqmsg= "(<font class=\"error\">"._REQUIRED."</font>)";
if(trim(empty($username))){
$user_err= $reqmsg;
}
if(empty($password)){
$pass_err= $reqmsg;
}
login_form();
exit();
}
$md5_pass = md5($password);
$sql = $db->sql_query("SELECT * FROM ".$prefix."_users WHERE username='$username' AND password='$md5_pass'");
$login_check = $db->sql_numrows($sql);
if($login_check > 0){
$row = $db->sql_fetchrow($sql);
$userid = $row['userid'];
$username = $row['username'];
$password = $row['password'];
$ipaddress = $row['ipaddress'];
$isactive = $row['isactive'];
if($isactive == 0){
echo "<br><br><br>";
echo "<font class=error>"._VALIDATE_ERROR_LOGIN."</font> ";
echo "<br><br>"._GOHOME."<br>";
exit();
}
$lastlogin = explode(" ", $row['lastlogin']);
$lastlogin_date = $lastlogin[0];
$lastlogin_time = $lastlogin[1];
$info = base64_encode("$userid|$username|$password|$lastlogin_date|$lastlogin_time");
if (isset($remember)){
setcookie("user","$info",time()+1209600);
}else{
setcookie("user","$info",0);
}
$db->sql_query("UPDATE ".$prefix."_users SET lastlogin=NOW() WHERE userid='$userid'");
msg_redirect(""._LOGIN_SUCCESS."","users.php","5");
}else{
$error_msg = "<font class=\"error\">"._LOGIN_ERROR."</font>";
unset($username);
unset($password);
login_form();
exit();
}
}
################################################################################
#------------------------------------------------------------------------------#
# logout
#------------------------------------------------------------------------------#
################################################################################
function Logout($user) {
global $db;
unset($user);
setcookie("user", false);
$user = "";
header("Location: users.php");
}
################################################################################
#------------------------------------------------------------------------------#
# Activate Function
#------------------------------------------------------------------------------#
################################################################################
function Activate(){
global $user, $db, $code, $prefix;
$code = intval($code);
if(isset($code) != 0){
$result = $db->sql_query("SELECT userid FROM ".$prefix."_users WHERE code='$code'");
if($db->sql_numrows($result) == 1){
$row = $db->sql_fetchrow($result);
$sql = $db->sql_query("UPDATE ".$prefix."_users SET isactive='1',code='0' WHERE userid='$row[userid]'");
msg_redirect(""._VALIDATE_DONE."","users.php","10");
}else{
echo _VALIDATE_ERROR;
}
}
}
################################################################################
#------------------------------------------------------------------------------#
# a switch for switching between functions
#------------------------------------------------------------------------------#
################################################################################
switch ($cat){
case "EditMyInfo":
EditMyInfo();
break;
case "do_EditMyInfo":
do_EditMyInfo();
break;
case "ChangePWD":
ChangePWD();
break;
case "do_ChangePWD":
do_ChangePWD();
break;
case "Forgot_pwd":
Forgot_pwd();
break;
case "do_Forgot_pwd":
do_Forgot_pwd();
break;
case "Register":
Register();
break;
case "do_Register":
do_Register();
break;
case "Logout":
Logout($user);
break;
case "Login":
Login();
break;
case "do_login":
do_login();
break;
case "Activate":
Activate();
break;
Default:
index($user);
Break;
}
?>
(Non è tutto il codice ma solo la parte interessata)