![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
15/03/2013, 08:24
|
![Avatar de emcl21](http://static.forosdelweb.com/customavatars/avatar495827_1.gif) | | | Fecha de Ingreso: marzo-2013
Mensajes: 3
Antigüedad: 11 años, 10 meses Puntos: 0 | |
Respuesta: Sesiones autenticando Aministrador y usuarios Normales En el Index metes este codigo en las primeras lineas :
<?
session_start();
if (isset($_SESSION['s_username'])) {
}else{
header ( "Location: login.php" );
}
?>
en la web Login.php
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login</title>
</head>
<body>
<table width="343" border="0" cellpadding="5" cellspacing="5">
<tr>
<td width="180" ><u class="Estilo4">Login:</u></td>
<td width="128"> </td>
</tr>
</table>
<form id="form1" name="form1" method="post" action="scriptLogin.php">
<table width="200" border="0" cellspacing="5" cellpadding="5">
<tr>
<td >Usuario:</td>
<td><input name="usuario" type="text" id="usuario" value="" size="10" maxlength="10" /></td>
</tr>
<tr>
<td >Contraseña:</td>
<td><input name="passwd" type="password" class="Estilo2" id="passwd" value="" size="10" /></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit" name="Submit" value="Aceptar" />
</label></td>
</tr>
</table>
</form>
<p ><? echo $_REQUEST[mensaje]; ?></p>
</body>
</html>
Y por ultimo el scriptlogin :
<?
require( "conectar.php" ); //conecta a bd
session_start();
$entro=false;
if ($_POST['usuario']) {
//Comprobacion del envio del nombre de usuario y password
$username=$_POST['usuario'];
$password=$_POST['passwd'];
if ($password==NULL) {
$mensaje="* La Contraseña no fue ingresado";
header ( "Location: login.php?mensaje=$mensaje");
$entro=true;
}
else {
$query = mysql_query("SELECT USUARIO,PASSWD FROM Vendedores WHERE USUARIO = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['PASSWD'] != $password) {
$mensaje="* Usuario o Contraseña incorrecto";
header ( "Location: login.php?mensaje=$mensaje" );
$entro=true;
}
else
{
$query = mysql_query("SELECT USUARIO,PASSWD FROM Vendedores WHERE USUARIO = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["s_username"] = $row['USUARIO'];
header ( "Location: index.php" );
$entro=true;
}
}
}
if ($entro==false)
{
$mensaje="* El usuario no fue ingresado";
header ( "Location: login.php?mensaje=$mensaje");
}
?> |