Jump to content

Formulario registro usuario

Recommended Posts

Hola comunidad!

Ayer hice una plantilla para que puedan registrarse usuarios a vuestro servidor (y no sé más que decir). Está basado en HTML-CSS-PHP 7.4, espero que os sirva.


	$conn = new mysqli('host', 'username', 'password');
	if(!$conn){echo 'Error al conectar a la base de datos.';}
	if (isset($_POST['RegisterUser'])) {
		$username_mt2 = $_POST['username_mt2'];
		$email_mt2 = $_POST['email_mt2'];
		$password_mt2 = $_POST['password_mt2'];
		$password_mt2_confirmation = $_POST['password_mt2_confirmation'];
		$securitycode = $_POST['securitycode'];
		$filter = preg_replace("/[^a-z\d\-=\[email protected]:\.]/i", "", $username_mt2);
		$alogin_verify = $conn->query("SELECT * FROM account.account WHERE login='$username_mt2'");$login_verify = $alogin_verify->fetch_array();
		$aemail_verify = $conn->query("SELECT * FROM account.account WHERE email='$email_mt2'");$email_verify = $aemail_verify->fetch_array();

		if(empty($username_mt2) && empty($email_mt2) && empty($password_mt2) && empty($password_mt2_confirmation)){
			$mensaje = "<div class='alert alert-danger'>Todos los campos son obligatorios.</div>";
		} elseif($username_mt2 !== $filter || strlen($username_mt2) < 4 || strlen($username_mt2) > 15){
			$mensaje = "<div class='alert alert-danger'>Inserta un nombre válido con mínimo 4 carácteres.</div>";
		} elseif($alogin_verify->num_rows > 0){
			$mensaje = "<div class='alert alert-danger'>El nombre de usuario está en uso.</div>";
		} elseif($aemail_verify->num_rows > 0){
			$mensaje = "<div class='alert alert-danger'>El e-mail está en uso.</div>";
		} elseif($password_mt2 == $password_mt2_confirmation){
				mysqli_query($conn, "INSERT INTO account.account (login,password,email,create_time,securitycode,channel_company,real_name) VALUES ('$username_mt2','". strtoupper("*" . sha1(sha1($password_mt2, true))) ."','$email_mt2','". date("Y-m-d H:i:s") ."','$securitycode','0','na')");
				$mensaje = "<div class='alert alert-success'>Te has registrado con éxito!</div>";
		} else {
			$mensaje = "<div class='alert alert-danger'>Las contraseñas no coinciden.</div>";
<!DOCTYPE html>
<html lang="en">
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/all.css">
	.divider-text {
		position: relative;
		text-align: center;
		margin-top: 15px;
		margin-bottom: 15px;
	body {
		background-color: #f8f9fa!important;
	.divider-text span {
		padding: 7px;
		font-size: 12px;
		position: relative;   
		z-index: 2;
	.divider-text:after {
		content: "";
		position: absolute;
		width: 100%;
		border-bottom: 1px solid #ddd;
		top: 55%;
		left: 0;
		z-index: 1;

<div class="container">
<div class="card" style="border: none;background: transparent;">
<article class="card-body mx-auto" style="max-width: 400px;">
	<h4 class="card-title mt-3 text-center">Create Account</h4>
	<p class="text-center">Get started with your free account</p>
	<?php echo $mensaje; ?>
	<form role="form" method="POST">
	<div class="form-group input-group">
		<div class="input-group-prepend">
		    <span class="input-group-text"> <i class="fa fa-user"></i> </span>
        <input maxlength="15" name="username_mt2" class="form-control" placeholder="Nombre de usuario" type="text">
    <div class="form-group input-group">
    	<div class="input-group-prepend">
		    <span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
        <input maxlength="50" name="email_mt2" class="form-control" placeholder="Correo electrónico" type="email">
    <div class="form-group input-group">
    	<div class="input-group-prepend">
		    <span class="input-group-text"> <i class="fa fa-lock"></i> </span>
        <input maxlength="50" name="password_mt2" class="form-control" placeholder="Contraseña" type="password">
	<div class="form-group input-group">
    	<div class="input-group-prepend">
		    <span class="input-group-text"> <i class="fa fa-lock"></i> </span>
        <input maxlength="50" name="password_mt2_confirmation" class="form-control" placeholder="Repetir contraseña" type="password">
	<div class="form-group input-group">
        <input maxlength="7" class="form-control" name="securitycode" placeholder="Código borrado" type="password">
    <div class="form-group">
        <button type="submit" name="RegisterUser" class="btn btn-primary btn-block"> Create Account  </button>
<center><a href="#" class="btn btn-success btn-lg active" role="button" aria-pressed="true">Descargar</a><br><br>
<i>Created by <a href="https://metin2zone.net/index.php?/profile/1061-zerocrazy/">Zerocrazy</a> & powered by <a href="https://codetech.es/">codetech</a>.</i></center>



Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...