Home  >  Article  >  Backend Development  >  How to implement user registration and login in php?

How to implement user registration and login in php?

coldplay.xixi
coldplay.xixiOriginal
2020-07-11 13:07:445870browse

php method to implement user registration and login: first create the database and form; then use the functions in the php file to operate the database to connect to the database; then modify the php file to implement login registration; and finally further improve and complete the login.

How to implement user registration and login in php?

php method to implement user registration and login:

1. Create database and form

The editor here is the database and form created through the phpmyadmin visual interface. Log in to the database after entering ip/phpmyadmin:

How to implement user registration and login in php?

Login After myadmin, create the database user and form usertext:

How to implement user registration and login in php?

How to implement user registration and login in php?

##2.php file to operate the database function

Here the editor first explains the role of the following PHP database operation functions:

(1)

mysqli_connect("localhost", "server name", "database password", "connection" Database name");

Parameter description:

"localhost", no need to change, novices should not change it to the IP address of the server, because the default user with permission to create a database is :

How to implement user registration and login in php?

"Connected database name" is the database. Do not fill in the form. The user in the first step is the database, and the usertext is the form.

(2)

mysqli_query()Function executes a query against the database:

mysqli_query(connection,query,resultmode);

Parameter description:

  • connection Required. Specifies the MySQL connection to use.

  • query Required, specifies the query string. (This is a string that stores mysql commands. The command content can only be realized by using this function)

  • resultmode Optional. a constant. Can be any of the following values:

  • MYSQLI_USE_RESULT (use this if you need to retrieve large amounts of data)

  • MYSQLI_STORE_RESULT (default)

eg:

(3)

mysqli_fetch_array() Function

Get a row from the result set as an associative array, or a numeric array , or both.

mysqli_fetch_array(result,resulttype);

Parameter description:

  • result Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().

  • resulttype Optional. Specifies what type of array should be produced. Can be one of the following values:

##MYSQLI_ASSOC

MYSQLI_NUM

MYSQLI_BOTH

3. Modify the php file to implement login registration

Let’s make changes to the loginaction.php and registeraction.php files

If the database creation is the same as in step 1, then You only need to fill in the user information in the two files:

mysqli_connect

("localhost", "server name", "database password", "user");. If the database name or form is different, you need to find the following statement:

    mysqli_connect(“localhost”, “server name”, “database password”, “user ”);
  • SELECT;
  • INSERT INTO; (only available in registeraction.php)
  • Change (database name) user and (form name) usertext in the above statement to your database name and form name.

4. Further improvement

Interested friends can try to create a hyperlink like the editor, and jump to the specified web page after successful login;

Find and exit in loginsucc.php and change login.php to another web page (if you write the file name directly, it needs to be placed in the same directory)

How to implement user registration and login in php?

Related learning Recommended:
PHP programming from entry to proficiency

The above is the detailed content of How to implement user registration and login in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn