hice un sistemita de login para usuarios ,la cual consta de.. un index, donde podes logear o darte de alta, la cual se llama index.htm , tambien un sesion.php donde muestro la info a los uusario q se logean o sino de lo contrario le salga un error ALERT, un usuarios.php
donde tengo el codigo para dar de alta a los usuarios a una BD mysql.
index.htm
Código HTML:
sesion.phpVer original
<!DOCTYPE HTML> <head> <meta http-equiv="content-type" content="text/html" /> <meta name="author" content="www.visualsac.net" /> <style type="text/css"> body{ background: black; color:white; font-family: trebuchet ms; font-style:italic; } .regis{ color:white; position: absolute; right:150px; font-family: trebuche ms; font-size: 20px; } #contenedor{ color:black; position:absolute; top:200px; right:500px; left:500px; border:5px solid; border-radius:25px; border-color:white; background:#C0DDEC; } </style> <script type="text/javascript"> function validar(){ if(document.formulario1.username.value.length==0){ alert('falta USUARIO') document.formulario1.username.focus(); document.formulario1.username.style.background='#F84926' return false;} else{ document.formulario1.username.style.background='white' } if(document.formulario1.password.value.length==0){ alert('falta CONTRASEÑA') document.formulario1.password.focus(); document.formulario1.password.style.background='#F84926' return false;} else{ document.formulario1.password.style.background='white' } document.formulario1.submit(); return false;} </script> </head> <?php session_start(); if(!empty($_SESSION['usuario'])){ echo"<table align='right' BgColor='white'>"; echo"</table>"; } ?> <body onload='document.formulario1.username.focus();'> <div id="contenedor"> <br /> <form name="formulario1" action="sesion.php" method='POST'> <table align="center"> <tr> </tr> <tr> </tr> <tr> </tr> </tr> </form> <br /> </div> </body> </html>
Código HTML:
Ver original
<html> <head> <style type="text/css"> body{ background: black; color:white; font-family: trebuchet ms; font-style:italic; font-size: 22px; text-align: center; } </style> </head> <body> <? $thank="usuarios.htm"; $host="localhost"; $root="root"; $pass=""; $base="usu"; $user=$_POST['username']; $contra=$_POST['password']; session_start(); $_SESSION['usuario']=$_POST['username']; $_SESSION['clave']=$_POST['password']; //conexión con la base de datos. $conexion=mysql_connect($host,$root,$pass); //Selección de la base de datos. mysql_select_db($base,$conexion); $query = mysql_query("SELECT * FROM usu WHERE username = '$user'") or die(mysql_error()); $datos = mysql_fetch_array($query); if($datos['password'] ==null ) { }else{ echo "<script> alert('Contraseña Correcta :D ');document.formulario.subtmit(); </script>"; $row = mysql_fetch_array($query); $_SESSION["s_username"] = $row['username']; $_SESSION["s_password"]= $row['password']; $_SESSION["s_mail"]= $row['mail']; $_SESSION["s_patch"]=$row['patch']; $_SESSION["n_nombre"]=$row['nombre']; $_SESSION["e_edad"]=$row['edad']; echo" Por ahora solo podes ver esto :D "; echo"<table align='center'>"; } echo"</table>"; ?> </body> <center><br /> </center> </html>
Usuarios.php
Código HTML:
Ver original
$host="localhost"; $root="root"; $pass=""; $base="usu"; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); $patch = "./upload/".$_FILES["file"]["name"]; $conexion=mysql_connect($host,$root,$pass) or die (" Error en la conexion"); mysql_select_db($base,$conexion) or die (" error en la base de datos "); $query=mysql_query("insert into usu(nombre,username,password,edad,mail,patch) values('$_POST[nom]','$_POST[usuario]','$_POST[pass]','$_POST[edad]','$_POST[mail]','$patch')",$conexion) or die ("alksdjaskldjklasjd eerror en la consulta xD "); mysql_close($conexion); header("location: indexu.htm");
EL PROBLEMA QUE TENGO ES EL SIGUIENTE, TODO ESTO FUNCIONA.. EL USUARIO SE PUEDE LOGEAR Y CERRAR SESION(NO PUSE EL CODIGO DE CERRAR)... LO QUE NO ME FUNCIONA ES QUE AL HACER EL NAVEGADOR HACIA ATRAS, LA SESION PIERDE EL LOGIN , ES DECIR, QUIERO QUE EL USUARIO INICIE SESION Y VEA LA PAGINA SESION.PHP Y VOLVER VOLVER HACIA ATRAS DESDE EL NAVEGADOR.. SE VEA UN BIENVENIDO Y TENGO EL NOMBRE DE LA SESION... DE HECHO LO HACE ESTE CODIGO , PERO CUANDO ME LOGEO CON CUALQUIER USUARIO Q NO ESTE REGISTRADO ME MUESTRA LA SESION IGUAL U.U..
ESPERO HAYAN ENTENDIDO UN POCO DEL CHOCLO QUE ESCRIBI :/
SALUDOS GENIOS :)