Código PHP:
<?php session_start();
$user = $_POST["user"];
$pass = md5($_POST["pass"]);
//datos para establecer la conexion con la base de mysql.
require_once "db.php";
function quitar($mensaje)
{
$nopermitidos = array("'",'\\','<','>',"\"");
$mensaje = str_replace($nopermitidos, "", $mensaje);
return $mensaje;
}
if(trim($user) != "" && trim($pass) != "")
{
// Puedes utilizar la funcion para eliminar algun caracter en especifico
//$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
//$password = $HTTP_POST_VARS["password"];
$result = mysql_query('SELECT level, pass, user FROM usuarios WHERE user=\''.$user.'\'');
$level0 = "usuario";
$level1 = "moderador";
$level2 = "administrador";
if($row = mysql_fetch_array($result)){
if($row["level"] == $level0){
}if($row["pass"] == $pass){
echo "<script languaje='javascript'>alert('Has sido logueado correctamente, Seras Redireccionado Enseguida.')</script>";
echo "<script language='javascript'>location.href = 'loggeduser.php';</script>";
}else{
echo "<script languaje='javascript'>alert('Password Incorrecto.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}if($row["level"] == $level1){
}if($row["pass"] == $pass){
echo "<script languaje='javascript'>alert('Has sido logueado correctamente, Seras Redireccionado Enseguida.')</script>";
echo "<script language='javascript'>location.href = 'loggedmod.php';</script>";
}else{
echo "<script languaje='javascript'>alert('Password Incorrecto.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}if($row["level"] == $level2){
if($row["pass"] == $pass){
$_SESSION["k_username"] = $row['user'];
echo "<script languaje='javascript'>alert('Has sido logueado correctamente, Seras Redireccionado Enseguida.')</script>";
echo '<SCRIPT LANGUAGE="javascript">
location.href = "loggedadmin.php";
</SCRIPT>';
}else{
echo "<script languaje='javascript'>alert('Password Incorrecto.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}
}}else{
echo "<script languaje='javascript'>alert('Nombre de Usuario NO exite en la base de datos.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}
mysql_free_result($result);
}else{
echo "<script languaje='javascript'>alert('Debe especificar un usuario y password')</script>";
}
mysql_close();
?>
<?php
$con = mysql_connect("localhost", "root", "");
$bd = mysql_select_db("metalcr18local", $con);
if(isset($_POST['enviar']) && $_POST['enviar'] != "")
{
$user = $_POST['user'];
$pass = md5($_POST['pass']);
$sql = "SELECT * FROM usuarios WHERE user = '$user' AND pass = '$pass' ";
$result = mysql_query($sql);
if (mysql_num_rows($result)==1){
$usuario_encontrado = mysql_fetch_object($result);
setcookie("user", $usuario_encontrado->user , time()+(3600), '/');
}else{
}
}
?>
Código PHP:
$result = mysql_query('SELECT level, pass, user FROM usuarios WHERE user=\''.$user.'\'');
$level0 = "usuario";
$level1 = "moderador";
$level2 = "administrador";
if($row = mysql_fetch_array($result)){
if($row["level"] == $level0){
}if($row["pass"] == $pass){
echo "<script languaje='javascript'>alert('Has sido logueado correctamente, Seras Redireccionado Enseguida.')</script>";
echo "<script language='javascript'>location.href = 'loggeduser.php';</script>";
}else{
echo "<script languaje='javascript'>alert('Password Incorrecto.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}if($row["level"] == $level1){
}if($row["pass"] == $pass){
echo "<script languaje='javascript'>alert('Has sido logueado correctamente, Seras Redireccionado Enseguida.')</script>";
echo "<script language='javascript'>location.href = 'loggedmod.php';</script>";
}else{
echo "<script languaje='javascript'>alert('Password Incorrecto.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}if($row["level"] == $level2){
if($row["pass"] == $pass){
$_SESSION["k_username"] = $row['user'];
echo "<script languaje='javascript'>alert('Has sido logueado correctamente, Seras Redireccionado Enseguida.')</script>";
echo '<SCRIPT LANGUAGE="javascript">
location.href = "loggedadmin.php";
</SCRIPT>';
}else{
echo "<script languaje='javascript'>alert('Password Incorrecto.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}
}}else{
echo "<script languaje='javascript'>alert('Nombre de Usuario NO exite en la base de datos.')</script>";
echo '<SCRIPT LANGUAGE="javascript">location.href = "log.php";</SCRIPT>';
}