Положение index php create an account html. Простая система регистрации пользователей. Продолжение доступно только участникам

Trackbacks (0)

Updated on: 2018-03-12

Posted on: 2016-12-21

Over time PHP has been adding features that promote the development of secure applications, as well deprecated or removed features that made it easy to write insecure code.

Read this tutorial to learn how to create a modern login and registration system that takes advantage of PHP security-focused features and uses jQuery to send AJAX requests and Bootstrap to provide a fast and nice user interface that can work regardless if you use other frameworks or not.



If you have questions or comments you can post a message as comment to this article or in its .

Change Log

2017-03-27: Added more download and install information using the composer tool.

2017-01-01: Updated the article to reflect that these continue to be secure practices in 2017




You need to be a registered user or login to post a comment Login Immediately with your account on:

Much of the websites have a registration form for your users to sign up and thus may benefit from some kind of privilege within the site. In this article we will see how to create a registration form in PHP and MySQL.

We will use simple tags and also we will use table tag to design the Sign-Up.html webpage. Let’s start:

Listing 1 : sign-up.html

Sign-Up Registration Form

Name
Email
UserName
Password
Confirm Password


Figure 1:

Description of sing-in.html webpage:

As you can see the Figure 1, there is a Registration form and it is asking few data about user. These are the common data which ask by any website from his users or visitors to create and ID and Password. We used table tag because to show the form fields on the webpage in a arrange form as you can see them on Figure 1. It’s looking so simple because we yet didn’t used CSS Style on it now let’s we use CSS styles and link the CSS style file with sing-up.html webpage.

Listing 2 : style.css

/*CSS File For Sign-Up webpage*/ #body-color{ background-color:#6699CC; } #Sign-Up{ background-image:url("sign-up.png"); background-size:500px 500px; background-repeat:no-repeat; background-attachment:fixed; background-position:center; margin-top:150px; margin-bottom:150px; margin-right:150px; margin-left:450px; padding:9px 35px; } #button{ border-radius:10px; width:100px; height:40px; background:#FF00FF; font-weight:bold; font-size:20px; }

Listing 3 : Link style.css with sign-up.html webpage



Figure 2:

Description of style.css file:

In the external CSS file we used some styles which could be look new for you. As we used an image in the background and set it in the center of the webpage. Which is become easy to use by the help of html div tag. As we used three div tag id’s. #button, #sing-up, and #body-color and we applied all CSS styles on them and now you can see the Figure 2, how much it’s looking beautiful and attractive. You can use many other CSS styles as like 2D and 3D CSS styles on it. It will look more beautiful than its looking now.

After these all simple works we are now going to create a database and a table to store all data in the database of new users. Before we go to create a table we should know that what we require from the user. As we designed the form we will create the table according to the registration form which you can see it on Figure 1 & 2.

Listing 3 : Query for table in MySQL

CREATE TABLE WebsiteUsers (userID int(9) NOT NULL auto_increment, fullname VARCHAR(50) NOT NULL, userName VARCHAR(40) NOT NULL, email VARCHAR(40) NOT NULL, pass VARCHAR(40) NOT NULL, PRIMARY KEY(userID));

Description of Listing 3:

One thing you should know that if you don’t have MySQL facility to use this query, so should follow my previous article about . from this link you will able to understand the installation and requirements. And how we can use it.

In the listing 3 query we used all those things which we need for the registration form. As there is Email, Full name, password, and user name variables. These variable will store data of the user, which he/she will input in the registration form in Figure 2 for the sing-up.

After these all works we are going to work with PHP programming which is a server side programming language. That’s why need to create a connection with the database.

Listing 4 : Database connection

Description of Listing 4:

We created a connection between the database and our webpages. But if you don’t know is it working or not so you use one thing more in the last check listing 5 for it.

Listing 5 : checking the connection of database connectivity

Description Listing 5:

In the Listing 5 I just tried to show you that you can check and confirm the connection between the database and PHP. And one thing more we will not use Listing 5 code in our sing-up webpage. Because it’s just to make you understand how you can check the MySQL connection.

Now we will write a PHP programming application to first check the availability of user and then store the user if he/she is a new user on the webpage.

Listing 6 : connectivity-sign-up.php

Description of connectivity-sign-up.php

In this PHP application I used simplest way to create a sign up application for the webpages. As you can see first we create a connection like listing 4. And then we used two functions the first function is SignUP() which is being called by the if statement from the last of the application, where its first confirming the pressing of sign up button. If it is pressed then it will call the SingUp function and this function will use a query of SELECT to fetch the data and compare them with userName and email which is currently entered from the user. If the userName and email is already present in the database so it will say sorry you are already registered

If the user is new as its currently userName and email ID is not present in the database so the If statement will call the NewUser() where it will store the all information of the new user. And the user will become a part of the webpage.



Figure 3

In the figure 3, user is entering data to sign up if the user is an old user of this webpage according to the database records. So the webpage will show a message the user is registered already if the user is new so the webpage will show a message the user’s registration is completed.



Figure 4:

As we entered data to the registration form (Figure 4), according to the database which userName and email we entered to the registration form for sing-up it’s already present in the database. So we should try a new userName and email address to sign-up with a new ID and Password.



Figure 5

In figure 5, it is confirming us that which userName and email id user has entered. Both are not present in the database records. So now a new ID and Password is created and the user is able to use his new ID and Password to get login next time.

Conclusion:

In this article we learnt the simplest way of creating a sign up webpage. We also learnt that how it deals with the database if we use PHP and MySQL. I tried to give you a basic knowledge about sign up webpage functionality. How it works at back end, and how we can change its look on front end. For any query don’t hesitate and comment.

Очень часто новички сталкиваются с проблемой написания регистрации у себя на сайте. В этой статье я расскажу как ее сделать.
Распишу все пошагово.

Шаг 1. Подключение к базе данных MySQL.
Создадим файл db_connect.php:

Mysql_connect("localhost", "пользователь", "пароль пользователя") or die("Ошибка соединения с MySQL!");
mysql_select_db("база данных") or die ("Ошибка соединения с базой данных MySQL!");
mysql_set_charset("utf8"); // выставляем кодировку базы данных

Шаг 2. Создадим таблицу для пользователей.

CREATE TABLE `users_profiles` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(32) NOT NULL,
`password` varchar(32) NOT NULL,
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Шаг 3. Создадим файл handler.php - этот файл будет содержать проверку на авторизацию пользователя.

Шаг 4. Пишем регистрацию.
Для этого создадим файл register.php и напишем в нем следующим код:

Шаг 6. Выход пользователя.
Каждый юзер должен выходить из сайта, если он этого хочет. Для этого создадим файл exit.php

Шаг 7. Создание главной страницы сайта.
Создадим последний файл - index.php

Для настройки создайте файл.htaccess и впишите в него следующее:

php_value register_globals 0
php_value magic_quotes_gpc 0

Php_value zlib.output_compression 1

AddDefaultCharset UTF-8

Тем кому лень делать это все, качайте

Hello, friends in this tutorial we will learn user registration and login using PHP stored procedure.
File structure for this tutorial
config.php
index.php
check_availability.php
login.php
welcome.php
logout.php
Structure of sql table tblregistration

CREATE TABLE `tblregistration` (`id` int(11) NOT NULL, `FullName` varchar(200) NOT NULL, `EmailId` varchar(200) NOT NULL, `Password` varchar(255) NOT NULL, `RegDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=latin1;

config.php

Create db configuration file using mysqli extension. Provide credential as per your configuration

index.php

Create a html form for user registration .

Register Full Name E-mail Password

Already registered. login here

Jquery / Ajax for user email availability

check_availability.php

In this page we will check the user email availability. Create a store procedure with name check availability
Store procedure code:

DELIMITER $ CREATE DEFINER=`root`@`localhost` PROCEDURE `checkavailbilty`(IN `email` VARCHAR(255)) NO SQL SELECT EmailId FROM tblregistration WHERE EmailId=email$ DELIMITER ;

Now create a store procedure for user registration.
Store procedure for user registration

DELIMITER $ CREATE DEFINER=`root`@`localhost` PROCEDURE `registration`(IN `fname` VARCHAR(200), IN `emailid` VARCHAR(200), IN `password` VARCHAR(255)) NO SQL insert into tblregistration(FullName,EmailId,Password) VALUES(fname,emailid,password)$ DELIMITER ;

After creation of store procedure execute the store procedure.

Here is the full code that we have written for registration (index.php ):

Registration using Store Procedure function checkAvailability() { $("#loaderIcon").show(); jQuery.ajax({ url: "check_availability.php", data:"emailid="+$("#email").val(), type: "POST", success:function(data){ $("#user-availability-status").html(data); $("#loaderIcon").hide(); }, error:function (){} }); } Register Full Name E-mail Password

Already registered. login here

login .php

Create a login form user login.

login

Not registered? Create an account

Now create a store procedure for login with name login.
Login store procedure:

DELIMITER $ CREATE DEFINER=`root`@`localhost` PROCEDURE `login`(IN `useremail` VARCHAR(255), IN `password` VARCHAR(255)) NO SQL SELECT EmailId,Password from tblregistration where EmailId=useremail and Password=password$ DELIMITER ;

Now execute the login store procedure