Ver Mensaje Individual
  #8 (permalink)  
Antiguo 22/08/2011, 16:38
Avatar de jatg
jatg
 
Fecha de Ingreso: abril-2011
Ubicación: caracas
Mensajes: 152
Antigüedad: 13 años, 11 meses
Puntos: 15
Respuesta: html form + php

Cita:
Iniciado por glx Ver Mensaje
Gracias por las respuestas, sin entender el porque de la solucion propuesta realice el cambio y todo sigue igual.

No logro entender esta sentencia, por lo tanto no puedo razonar el criterio aplicado.

action="guardar.php?accion=guardar"

Generalmente encuentro action=xxxx.php pero lo que sigue despues me marea ?accion=guardar
ok te lo voy a explicar detalladamente y pasito a pasito presta atencion

crea una base de datos y llamala users

user.sql

CREATE TABLE `users` (
`ID` int(11) NOT NULL auto_increment,
`Username` varchar(255) NOT NULL,
`Password` varchar(255) NOT NULL,
`Temp_pass` varchar(55) default NULL,
`Temp_pass_active` tinyint(1) NOT NULL default '0',
`Email` varchar(255) NOT NULL,
`Active` int(11) NOT NULL default '0',
`Level_access` int(11) NOT NULL default '2',
`Random_key` varchar(32) default NULL,
PRIMARY KEY (`ID`),
UNIQUE KEY `Username` (`Username`),
UNIQUE KEY `Email` (`Email`)
) ENGINE=MyISAM;


ok ahora crea un formulario .html y llamalo registrar.html


al primero lo llamaremos registrar.html

registrar.html

Código PHP:
Ver original
  1. <?php
  2. require_once('db.php');
  3. include('functions.php');
  4.  
  5.     if(isset($_POST['register']))
  6.     {
  7.         if($_POST['username']!='' && $_POST['password']!='' && $_POST['password']==$_POST['password_confirmed'] && $_POST['email']!='' && valid_email($_POST['email'])==TRUE && checkUnique('Username', $_POST['username'])==TRUE && checkUnique('Email', $_POST['email'])==TRUE)
  8.         {
  9.        
  10.             $query = mysql_query("INSERT INTO users (`Username` , `Password`, `Email`, `Random_key`) VALUES ('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string(md5($_POST['password']))."', '".mysql_real_escape_string($_POST['email'])."', '".random_string('alnum', 32)."')") or die(mysql_error());
  11.            
  12.             $getUser = mysql_query("SELECT ID, Username, Email, Random_key FROM users WHERE Username = '".mysql_real_escape_string($_POST['username'])."'") or die(mysql_error());
  13.    
  14.             if(mysql_num_rows($getUser)==1)
  15.             {//there's only one MATRIX :PP
  16.            
  17.                 $row = mysql_fetch_assoc($getUser);
  18.                 $headers =  'From: [email protected]' . "\r\n" .
  19.                             'Reply-To: [email protected]' . "\r\n" .
  20.                             'X-Mailer: PHP/' . phpversion();
  21.                 $subject = "Activation email from ourdomainhere.com";
  22.                 $message = "Dear ".$row['Username'].", this is your activation link to join our website. In order to confirm your membership please click on the following link: http://www.ourdomainhere.com/confirm.php?ID=".$row['ID']."&amp;key=".$row['Random_key']." Thank you for joining";
  23.                 if(mail($row['Email'], $subject, $message, $headers))
  24.                 {//we show the good guy only in one case and the bad one for the rest.
  25.                     $msg = 'Account created. Please login to the email you provided during registration and confirm your membership.';
  26.                 }
  27.                 else {
  28.                     $error = 'I created the account but failed sending the validation email out. Please inform my boss about this cancer of mine';
  29.                 }
  30.             }
  31.             else {
  32.                 $error = 'You just made possible the old guy (the impossible). Please inform my boss in order to give you the price for this.';
  33.             }
  34.                            
  35.         }
  36.         else {     
  37.             $error = 'There was an error in your data. Please make sure you filled in all the required data, you provided a valid email address and that the password fields match';   
  38.         }
  39.     }
  40. ?>
  41. <?php if(isset($error)){ echo $error;}?>
  42. <?php if(isset($msg)){ echo $msg;} else {//if we have a mesage we don't need this form again.?>
  43. <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  44.     Username: <input type="text" id="username" name="username" size="32" value="<?php if(isset($_POST['username'])){echo $_POST['username'];}?>" /><br />
  45.     Password: <input type="password" id="password" name="password" size="32" value="" /><br />
  46.     Re-password: <input type="password" id="password_confirmed" name="password_confirmed" size="32" value="" /><br />
  47.     Email: <input type="text" id="email" name="email" size="32" value="<?php if(isset($_POST['email'])){echo $_POST['email'];}?>" /><br />
  48.     <input type="submit" name="register" value="register" /><br />
  49. </form>
  50. <? } ?>

ok ahora crearemos 4 archivos de tipo .php

aqui los 4 archivos


confirm.php

Código PHP:
Ver original
  1. <?php
  2. require_once('db.php');
  3. include('functions.php');
  4.  
  5.     if($_GET['ID']!='' && numeric($_GET['ID'])==TRUE && strlen($_GET['key'])==32 && alpha_numeric($_GET['key'])==TRUE)
  6.     {
  7.  
  8.         $query = mysql_query("SELECT ID, Random_key, Active FROM users WHERE ID = '".mysql_real_escape_string($_GET['ID'])."'");
  9.        
  10.         if(mysql_num_rows($query)==1)
  11.         {
  12.             $row = mysql_fetch_assoc($query);
  13.             if($row['Active']==1)
  14.             {
  15.                 $error = 'This member is already active !';
  16.             }
  17.             elseif($row['Random_key']!=$_GET['key'])
  18.             {
  19.                 $error = 'The confirmation key that was generated for this member does not match with the one entered !';
  20.             }
  21.             else
  22.             {
  23.                 $update = mysql_query("UPDATE users SET Active=1 WHERE ID='".mysql_real_escape_string($row['ID'])."'") or die(mysql_error());
  24.                 $msg = 'Congratulations !  You just confirmed your membership !';
  25.             }
  26.         }
  27.         else {
  28.        
  29.             $error = 'User not found !';
  30.        
  31.         }
  32.  
  33.     }
  34.     else {
  35.  
  36.         $error = 'Invalid data provided !';
  37.  
  38.     }
  39.  
  40.     if(isset($error))
  41.     {
  42.         echo $error;
  43.     }
  44.     else {
  45.         echo $msg;
  46.     }
  47. ?>

confir_passwoord.php

Código PHP:
Ver original
  1. <?php
  2. require_once('db.php');
  3. include('functions.php');
  4.  
  5.     $query = mysql_query("SELECT * FROM users WHERE ID = '".mysql_real_escape_string($_GET['ID'])."'");
  6.  
  7.     if(mysql_num_rows($query)==1)
  8.     {
  9.         $row = mysql_fetch_assoc($query);
  10.         if($row['Temp_pass']==$_GET['new'] && $row['Temp_pass_active']==1)
  11.         {
  12.             $update = mysql_query("UPDATE users SET Pass = '".md5(mysql_real_escape_string($_GET['new']))."', Temp_pass_active=0 WHERE ID = '".mysql_real_escape_string($_GET['ID'])."'");
  13.             $msg = 'Your new password has been confirmed. You may login using it.';
  14.         }
  15.         else
  16.         {
  17.             $error = 'The new password is already confirmed or is incorrect';
  18.         }
  19.     }
  20.     else {
  21.         $error = 'You are trying to confirm a new password for an unexisting member';
  22.     }
  23.  
  24.     if(isset($error))
  25.     {
  26.         echo $error;
  27.     }
  28.     else {
  29.         echo $msg;
  30.     }
  31. ?>


sigo en la proxima cita continuar
__________________
www.josealexis.net