Ver Mensaje Individual
  #5 (permalink)  
Antiguo 18/04/2011, 18:58
Avatar de camilo1012
camilo1012
 
Fecha de Ingreso: febrero-2011
Mensajes: 46
Antigüedad: 13 años, 2 meses
Puntos: 1
Respuesta: Sistema de cuentas con mysql

Los codigos son :

index.php
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Inicio</title>
<style type="text/css">

.roundedcornr_box_672216 {
   background: #003399;
}
.roundedcornr_top_672216 div {
   background: url(roundedcornr_672216_tl.png) no-repeat top left;
}
.roundedcornr_top_672216 {
   background: url(roundedcornr_672216_tr.png) no-repeat top right;
}
.roundedcornr_bottom_672216 div {
   background: url(roundedcornr_672216_bl.png) no-repeat bottom left;
}
.roundedcornr_bottom_672216 {
   background: url(roundedcornr_672216_br.png) no-repeat bottom right;
}

.roundedcornr_top_672216 div, .roundedcornr_top_672216, 
.roundedcornr_bottom_672216 div, .roundedcornr_bottom_672216 {
   width: 100%;
   height: 9px;
   font-size: 1px;
}
.roundedcornr_content_672216 { margin: 0 9px; }
a:link {
	color: #000;
}
a:visited {
	color: #000;
}
body,td,th {
	color: #000;
}
a:hover {
	color: #000;
}
a:active {
	color: #000;
}
</style>
</head>

<body>
<?php session_start();
 
echo 'Bienvenido, ';
 
if (isset($_SESSION['k_username'])) {
    echo '<b>'.$_SESSION['k_username'].'</b>.';
	echo '<p><a href="logout.php">Logout</a></p>';
?>
	<div align="center">
<table width="900" border="0" cellpadding="0">
    <th height="246" scope="col">
    <div class="roundedcornr_box_672216">
   <div class="roundedcornr_top_672216"><div></div></div>
      <div class="roundedcornr_content_672216">
      <table width="850" border="0" cellpadding="0">
  <tr>
    <th height="51" scope="col"><h2>Insertar Registros</h2></th>
  </tr>
  <tr>
    <td height="108" align="center" valign="middle"><table width="750" border="0" cellpadding="0">
      <tr>
        <th width="184" align="left" valign="middle" scope="col"><a href="insertar1.php">Insertar noticia en index</a></th>
        <th width="184" align="left" valign="middle" scope="col"><a href="insertarcomu1.php">Insertar un Comunicado</a></th>
        <th width="184" align="left" valign="middle" scope="col"><a href="insertaralum1.php">Insertar Comunicado del Centro de Estudiantes</a></th>
        <th width="184" align="left" valign="middle" scope="col">&nbsp;</th>
        </tr>
      </table></td>
  </tr>
</table>
</div>
   <div class="roundedcornr_bottom_672216"><div></div></div>
</div>
</th>
</table>
</div>
<?
}else{
    echo '<p><a href="login.php">Login</a></p>';
}
?>
</body>
</html>
login.php :
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Login</title>
</head>

<body>
<form action="validar_usuario.php" method="post">
Usuario:<input type="text" name="usuario" size="20" maxlength="20" />
<br />
Password:<input type="password" name="password" size="10" maxlength="10" />
<br />
<input type="submit" value="Ingresar" />
</form>
</body>
</html>
logout.php :
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Salir</title>
</head>

<body>
<?php session_start();
// Borramos toda la sesion
session_destroy();
echo 'Ha terminado la session <p><meta http-equiv="Refresh" content="3;URL=index.php"/>Redireccionando...</p>';
?>
<SCRIPT LANGUAGE="javascript">
location.href = "index.php";
</SCRIPT>
</body>
</html>
validar_usuario.php :
Código:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Validar usuario</title>
<style type="text/css">

.roundedcornr_box_672216 {
   background: #003399;
}
.roundedcornr_top_672216 div {
   background: url(roundedcornr_672216_tl.png) no-repeat top left;
}
.roundedcornr_top_672216 {
   background: url(roundedcornr_672216_tr.png) no-repeat top right;
}
.roundedcornr_bottom_672216 div {
   background: url(roundedcornr_672216_bl.png) no-repeat bottom left;
}
.roundedcornr_bottom_672216 {
   background: url(roundedcornr_672216_br.png) no-repeat bottom right;
}

.roundedcornr_top_672216 div, .roundedcornr_top_672216, 
.roundedcornr_bottom_672216 div, .roundedcornr_bottom_672216 {
   width: 100%;
   height: 9px;
   font-size: 1px;
}
.roundedcornr_content_672216 { margin: 0 9px; }
body,td,th {
	color: #000;
}
a:link {
	color: #000;
}
a:visited {
	color: #000;
}
a:hover {
	color: #000;
}
a:active {
	color: #000;
}
</style>
</head>

<body>
<?php session_start();
 
//datos para establecer la conexion con la base de mysql.
mysql_connect('127.0.0.1','root','110695')or die ('Ha fallado la conexi&oacute;n: '.mysql_error());
mysql_select_db('lab')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
 
function quitar($mensaje)
{
    $nopermitidos = array("'",'\\','<','>',"\"");
    $mensaje = str_replace($nopermitidos, "", $mensaje);
    return $mensaje;
}     
 
if(trim($HTTP_POST_VARS["usuario"]) != "" && trim($HTTP_POST_VARS["password"]) != "")
{
    // Puedes utilizar la funcion para eliminar algun caracter en especifico
    //$usuario = strtolower(quitar($HTTP_POST_VARS["usuario"]));
    //$password = $HTTP_POST_VARS["password"];
   
    // o puedes convertir los a su entidad HTML aplicable con htmlentities
    $usuario = strtolower(htmlentities($HTTP_POST_VARS["usuario"], ENT_QUOTES));   
    $password = $HTTP_POST_VARS["password"];
     
 
    $result = mysql_query('SELECT password, usuario FROM usuarios WHERE usuario=\''.$usuario.'\'');
    if($row = mysql_fetch_array($result)){
        if($row["password"] == $password){
 
            $_SESSION["k_username"] = $row['usuario'];
			
           
            echo 'Has sido logueado correctamente '.$_SESSION['k_username'].' <p>';
			echo '<meta http-equiv="Refresh" content="1;URL=index.php"/>Redireccionando...</p>';
			
            //Elimina el siguiente comentario si quieres que re-dirigir autom&aacute;ticamente a index.php
           
            /*Ingreso exitoso, ahora sera dirigido a la pagina principal.
            <SCRIPT LANGUAGE="javascript">
            location.href = "index.php";
            </SCRIPT>*/
 
        }else{
            echo 'Password incorrecto';
        }
    }else{
        echo 'Usuario no existente en la base de datos';
    }
    mysql_free_result($result);
}else{
    echo 'Debe especificar un usuario y password<br>';
	echo '<a href="login.php">Volver</a>';
}
mysql_close();
?>
</body>
</html>