gracias
Código PHP:
<?php
//
//THIS FOLLOWING SCRIPT HAS BEEN CREATED BY JOE COOPER ([email protected]) ON 10/MARCH/06 FOR "PROJECT X"
//This is the user login script that allows the user to enter their username or password into the form to login
//The password uses MD5 encryption
//
include("codes/db.php");
include("codes/manejoSesiones.class.php");
ini_set('session.gc_maxlifetime', 350);
ini_set('session.cookie_lifetime', 350);
$sesionOA = new manejoSesiones();
session_set_save_handler(array(&$sesionOA,'abrirSesion'),array(&$sesionOA,'cerrarSesion'),array(&$sesionOA,'leerSesion'),array(&$sesionOA,'escribirSesion'),array(&$sesionOA,'borrarSesion'),array(&$sesionOA,'recolector'));
session_start(); //start the session
$username=$_POST['usuario']; //Get the username the user has entered
$password=$_POST['pass']; //Get the password the user has entered
$password=md5($password); //turn the password they entered into md5 to compare with the DB
$loginname=$_SESSION['username'];
//check to see if logged in allready
if (isset($_SESSION['loggedin'])){
die("You are logged in<br><a href='logout.php'>Click here to logout</a>");
//if not logged in, then run other script instead
}else{
//find if the page was enterd by the login button
if (isset($_POST['submit'])){
//if username was entered, continue
if($username && $password){
$result=mysql_query($sql);
//If the user gets to here, then they have typed both a username and password, so we may now go onto finding out if they excist in the DB
$sql="SELECT * FROM administradores WHERE (administrador='$username') AND password='$password'"; //get rows where the username feild matches the username or email feild in the database with same password
$result=mysql_query($sql);
//check to see if the account is activated
$moorow=mysql_fetch_array($result);
//if there was a row returned, then obiously there is an account with the correct username/password. They may login!
if (mysql_num_rows($result) > 0){
$_SESSION['loggedin']="TRUE"; //set the global session varible for loggedin to true
$row=mysql_fetch_array($result);
$_SESSION['username']=$username;
//setcookie("usuario", $username, time() + 31536000);
// setcookie("pass", $password, time() + 31536000);
$sql="SELECT sexo FROM administradores WHERE administrador='$username'";
$result=mysql_query($sql);
$sex=mysql_result($result,0,0);
$_SESSION['sexo']=$sex;
mysql_free_result($result);
header("Location: admin.php");
//die("Welcome $username You are now logged in");
}else{
header("Location: index.php?msg=err");
}
}else{
header("Location: index.php?msg=not");
}
}
}
?>