Foros del Web » Programando para Internet » PHP »

sistema de registro y login

Estas en el tema de sistema de registro y login en el foro de PHP en Foros del Web. [COLOR="RoyalBlue"]HOLA QUISIERA SABER SI ALGUIEN ME PUEDE AYUDAR CON ESTE PROBLEMA. LO QUE QUIERO ES LO SIGUIENTE : ingresar.php @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código PHP: Ver original ...
  #1 (permalink)  
Antiguo 03/06/2011, 06:02
 
Fecha de Ingreso: junio-2011
Mensajes: 39
Antigüedad: 12 años, 10 meses
Puntos: 2
sistema de registro y login

[COLOR="RoyalBlue"]HOLA QUISIERA SABER SI ALGUIEN ME PUEDE AYUDAR CON ESTE PROBLEMA.

LO QUE QUIERO ES LO SIGUIENTE :

ingresar.php

Código PHP:
Ver original
  1. <?php require_once('Connections/ofertas.php'); ?>
  2. <?php
  3. // *** Validate request to login to this site.
  4. if (!isset($_SESSION)) {
  5. }
  6.  
  7. $loginFormAction = $_SERVER['PHP_SELF'];
  8. if (isset($_GET['accesscheck'])) {
  9.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  10. }
  11.  
  12. if (isset($_POST['Email'])) {
  13.   $loginUsername=$_POST['Email'];
  14.   $password=$_POST['Clave'];
  15.   $MM_fldUserAuthorization = "";
  16.   $MM_redirectLoginSuccess = "micuenta.php";
  17.   $MM_redirectLoginFailed = "no_usuario.php";
  18.   $MM_redirecttoReferrer = false;
  19.   mysql_select_db($database_ofertas, $ofertas);
  20.  
  21.   $LoginRS__query=sprintf("SELECT Email, Clave FROM usuarios WHERE Email='%s' AND Clave='%s'",
  22.     get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  23.    
  24.   $LoginRS = mysql_query($LoginRS__query, $ofertas) or die(mysql_error());
  25.   $loginFoundUser = mysql_num_rows($LoginRS);
  26.   if ($loginFoundUser) {
  27.      $loginStrGroup = "";
  28.    
  29.     //declare two session variables and assign them
  30.     $_SESSION['MM_Username'] = $loginUsername;
  31.     $_SESSION['MM_UserGroup'] = $loginStrGroup;      
  32.  
  33.     if (isset($_SESSION['PrevUrl']) && false) {
  34.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
  35.     }
  36.     header("Location: " . $MM_redirectLoginSuccess );
  37.   }
  38.   else {
  39.     header("Location: ". $MM_redirectLoginFailed );
  40.   }
  41. }
  42. ?>
  43. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  44. <html xmlns="http://www.w3.org/1999/xhtml">
  45. <head>
  46. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  47. <title>Documento sin t&iacute;tulo</title>
  48. <style type="text/css">
  49. <!--
  50. #Layer1 {
  51.     position:absolute;
  52.     left:431px;
  53.     top:168px;
  54.     width:95px;
  55.     height:145px;
  56.     z-index:1;
  57. }
  58. -->
  59. </style>
  60. </head>
  61.  
  62. <body>
  63. <div id="Layer1">
  64.   <form method="POST" name="form1" action="<?php echo $loginFormAction; ?>">
  65.     <table width="382" align="center">
  66.       <tr valign="baseline">
  67.         <td width="38" align="right" nowrap>Email:</td>
  68.         <td width="269"><input type="text" name="Email" value="" size="30">
  69.         <img src="imagenes/Mail_16x16.png" width="16" height="16" /></td>
  70.       </tr>
  71.       <tr valign="baseline">
  72.         <td nowrap align="right">Clave:</td>
  73.         <td><input type="password" name="Clave" value="" size="30">
  74.         <img src="imagenes/candado.jpg" width="16" height="16" /></td>
  75.       </tr>
  76.       <tr valign="baseline">
  77.         <td nowrap align="right">&nbsp;</td>
  78.         <td>
  79.           <div align="center">
  80.             <input type="submit" value="Ingresar">
  81.             </div></td></tr>
  82.     </table>
  83.     <input type="hidden" name="id_usuario" value="">
  84.   </form>
  85.   </div>
  86. </body>
  87. </html>


lo que necesito es si alguien me ayuda con el login a validarlo.
con el registro a que solo se pueda registrar un mismo e-mail, nombre y clave en la base de datos y como hacer para que una ves que este logeado, si apreta en el login o registro este le indique que ya esta registrado o logeado?
  #2 (permalink)  
Antiguo 03/06/2011, 06:03
 
Fecha de Ingreso: junio-2011
Mensajes: 39
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: sistema de registro y login

PARTE DOS (2)

registrate.php

Código PHP:
Ver original
  1. <?php require_once('Connections/ofertas.php'); ?>
  2. <?php
  3. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  4. {
  5.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  6.  
  7.   switch ($theType) {
  8.     case "text":
  9.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  10.       break;    
  11.     case "long":
  12.     case "int":
  13.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  14.       break;
  15.     case "double":
  16.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  17.       break;
  18.     case "date":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;
  21.     case "defined":
  22.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  23.       break;
  24.   }
  25.   return $theValue;
  26. }
  27.  
  28. $editFormAction = $_SERVER['PHP_SELF'];
  29. if (isset($_SERVER['QUERY_STRING'])) {
  30.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  31. }
  32.  
  33. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  34.   $insertSQL = sprintf("INSERT INTO usuarios (id_usuario, Nombre, Apellido, Usuario, Clave, `Repetirclave`, Email, `CodigoPostal`, Telefono, Celular, Departamento, Domicilio, Descripcion) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
  35.                        GetSQLValueString($_POST['id_usuario'], "int"),
  36.                        GetSQLValueString($_POST['Nombre'], "text"),
  37.                        GetSQLValueString($_POST['Apellido'], "text"),
  38.                        GetSQLValueString($_POST['Usuario'], "text"),
  39.                        GetSQLValueString($_POST['Clave'], "text"),
  40.                        GetSQLValueString($_POST['Repetir_clave'], "text"),
  41.                        GetSQLValueString($_POST['Email'], "text"),
  42.                        GetSQLValueString($_POST['Codigo_Postal'], "int"),
  43.                        GetSQLValueString($_POST['Telefono'], "int"),
  44.                        GetSQLValueString($_POST['Celular'], "int"),
  45.                        GetSQLValueString($_POST['Departamento'], "text"),
  46.                        GetSQLValueString($_POST['Domicilio'], "text"),
  47.                        GetSQLValueString($_POST['Descripcion'], "text"));
  48.  
  49.   mysql_select_db($database_ofertas, $ofertas);
  50.   $Result1 = mysql_query($insertSQL, $ofertas) or die(mysql_error());
  51.  
  52.   $insertGoTo = "registrado.php";
  53.   if (isset($_SERVER['QUERY_STRING'])) {
  54.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  55.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  56.   }
  57.   header(sprintf("Location: %s", $insertGoTo));
  58. }
  59. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  60. <html xmlns="http://www.w3.org/1999/xhtml">
  61. <head>
  62. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  63. <title></title>
  64. <script type="text/JavaScript">
  65. <!--
  66. function MM_findObj(n, d) { //v4.01
  67.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  68.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  69.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  70.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  71.   if(!x && d.getElementById) x=d.getElementById(n); return x;
  72. }
  73.  
  74. function MM_validateForm() { //v4.0
  75.   var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  76.   for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
  77.     if (val) { nm=val.name; if ((val=val.value)!="") {
  78.       if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  79.         if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  80.       } else if (test!='R') { num = parseFloat(val);
  81.         if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  82.         if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  83.           min=test.substring(8,p); max=test.substring(p+1);
  84.           if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  85.     } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  86.   } if (errors) alert('The following error(s) occurred:\n'+errors);
  87.   document.MM_returnValue = (errors == '');
  88. }
  89. //-->
  90. </script>
  91. </head>
  92.  
  93. <body>
  94. <div id="registrete">
  95.   <form action="<?php echo $editFormAction; ?>" method="post" name="form1" onsubmit="MM_validateForm('Nombre','','R','Usuario','','R','Email','','RisEmail','Codigo_Postal','','NisNum','Telefono','','NisNum','Celular','','NisNum','Domicilio','','R','Clave','','R','Repetir_clave','','R');return document.MM_returnValue">
  96.     <table align="center">
  97.       <tr valign="baseline">
  98.         <td nowrap align="right">Nombre:</td>
  99.         <td><input type="text" name="Nombre" value="" size="32"></td>
  100.         <td>Apellido :
  101.           <input type="text" name="Apellido" value="" size="32" /></td>
  102.       </tr>
  103.       <tr valign="baseline">
  104.         <td colspan="3" align="right" nowrap>&nbsp;</td>
  105.       </tr>
  106.       <tr valign="baseline">
  107.         <td height="41" align="right" nowrap>Usuario:</td>
  108.         <td><input type="text" name="Usuario" value="" size="32"></td>
  109.         <td>&nbsp;</td>
  110.       </tr>
  111.       <tr valign="baseline">
  112.         <td nowrap align="right">Clave:</td>
  113.         <td><input type="password" name="Clave" value="" size="32"></td>
  114.         <td>Repetir :
  115.           <input type="password" name="Repetir_clave" value="" size="32" /></td>
  116.       </tr>
  117.       <tr valign="baseline">
  118.         <td colspan="3" align="right" nowrap>&nbsp;</td>
  119.       </tr>
  120.       <tr valign="baseline">
  121.         <td height="39" align="right" nowrap>E-mail:</td>
  122.         <td colspan="2"><input type="text" name="Email" value="" size="32"></td>
  123.       </tr>
  124.       <tr valign="baseline">
  125.         <td height="38" align="right" nowrap>C&oacute;digo Postal:</td>
  126.         <td colspan="2"><input type="text" name="Codigo_Postal" value="" size="32"></td>
  127.       </tr>
  128.       <tr valign="baseline">
  129.         <td nowrap align="right">Tel&eacute;fono:</td>
  130.         <td><input type="text" name="Telefono" value="" size="32"></td>
  131.         <td>Celular :
  132.           <input type="text" name="Celular" value="" size="32" /></td>
  133.       </tr>
  134.       <tr valign="baseline">
  135.         <td colspan="3" align="right" nowrap>&nbsp;</td>
  136.       </tr>
  137.       <tr valign="baseline">
  138.         <td nowrap align="right">Departamento:</td>
  139.         <td><input type="text" name="Departamento" value="" size="32"></td>
  140.         <td>Domicilio:
  141.           <input type="text" name="Domicilio" value="" size="32" /></td>
  142.       </tr>
  143.       <tr valign="baseline">
  144.         <td colspan="3" align="right" nowrap>&nbsp;</td>
  145.       </tr>
  146.       <tr valign="baseline">
  147.         <td nowrap align="right" valign="top">Descripci&oacute;n:</td>
  148.         <td colspan="2"><textarea name="Descripcion" cols="50" rows="5"></textarea>        </td>
  149.       </tr>
  150.       <tr valign="baseline">
  151.         <td nowrap align="right">&nbsp;</td>
  152.         <td colspan="2"><div align="center">
  153.           <input type="submit" value="Registrarse">
  154.           <input type="reset" name="Submit" value="Restablecer" />
  155.         </div></td>
  156.       </tr>
  157.     </table>
  158.     <input type="hidden" name="id_usuario" value="">
  159.     <input type="hidden" name="MM_insert" value="form1">
  160.   </form>
  161.   <p>&nbsp;</p>
  162. </div>
  163. </body>
  164. </html>
  #3 (permalink)  
Antiguo 03/06/2011, 06:06
 
Fecha de Ingreso: junio-2011
Mensajes: 39
Antigüedad: 12 años, 10 meses
Puntos: 2
Respuesta: sistema de registro y login

PARTE TRES (3)

Y como hacer para que en todas las paginas que tenga el sitio sepa si esta logeado o no?

y como hacer para que el solo tenga acceso a su perfil, digo que todo el mundo pueda ver lo que el indique y que al apretar en el perfil o mi cuenta vaya solo si esta logeado...
  #4 (permalink)  
Antiguo 03/06/2011, 06:33
 
Fecha de Ingreso: junio-2011
Ubicación: Barcelona
Mensajes: 212
Antigüedad: 12 años, 10 meses
Puntos: 17
Respuesta: sistema de registro y login

Hola 'ofertasdiairias' que quieres hacer con todo eso? Lo digo por que si solo quieres un sistema de registro y usuarios con las caracteristicas que as dicho:

"egistro a que solo se pueda registrar un mismo e-mail, nombre y clave en la base de datos y como hacer para que una ves que este logeado, si apreta en el login o registro este le indique que ya esta registrado o logeado'

no hace falta tanto codigo y alomejor hacer algo en complejo alomejor lo que buscas lo tienes en un CMS. Un saludo!
  #5 (permalink)  
Antiguo 03/06/2011, 06:43
 
Fecha de Ingreso: marzo-2011
Mensajes: 107
Antigüedad: 13 años
Puntos: 22
Respuesta: sistema de registro y login

Puedes poner un include() con un archivo que tenga una capa con sus datos (nick, pass)

Para que acceda a su perfil, has a tener 2 id: uno el perfil que estoy viendo, y otro el de sesion (el mio)

Código PHP:
if($idperfil == $idsesion)
{
   echo 
'opciones de perfil';
}
else
{
   echo 
'ver perfil';

  #6 (permalink)  
Antiguo 03/06/2011, 06:49
Avatar de Silkon  
Fecha de Ingreso: mayo-2011
Ubicación: Lugo
Mensajes: 201
Antigüedad: 12 años, 11 meses
Puntos: 20
Respuesta: sistema de registro y login

Validarlo que te refieres? que sea valido en W3C?
  #7 (permalink)  
Antiguo 03/06/2011, 06:57
 
Fecha de Ingreso: marzo-2011
Mensajes: 107
Antigüedad: 13 años
Puntos: 22
Respuesta: sistema de registro y login

Será validar datos XD
  #8 (permalink)  
Antiguo 03/06/2011, 07:01
Avatar de bUllan9ebrio  
Fecha de Ingreso: enero-2011
Ubicación: Chile
Mensajes: 1.128
Antigüedad: 13 años, 2 meses
Puntos: 128
Respuesta: sistema de registro y login

con el registro a que solo se pueda registrar un mismo e-mail, nombre y clave en la base de datos y como hacer para que una ves que este logeado, si apreta en el login o registro este le indique que ya esta registrado o logeado?

Validaciones las puedes realizar por JS, si pasas por las faq creo que encontraras mas de una solucion a tu problema, respecto a que el sistema indique si esta registrado o logeado, no es nada mas que una simple consulta a tu base de datos :

Código PHP:
Ver original
  1. SELECT usuario FROM tabla WHERE usuario='usuario' and clave='clave'

y luego el insert en caso de no estar registrado, para saber si esta logeado podrias tener un campo que se active en tu base de datos cuando un usuario se logeo y cuando sale del sistema
__________________
Si no vivimos como pensamos, pronto empezaremos a pensar como vivimos.
Más vale un Gracias sincero, que un número que aumente "popularidad" ¬¬°

Universidad de chile, campeón

Etiquetas: login, registro, sistema
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:36.