How to create a register / login.php file for my site?

I am trying to create a website that allows me to create a registration form as well as a login form. I have all the HTML and CSS settings, but I need php to process the form. I need this to be checked too.

The following is the form code for the login form:

<form action="login.php" autocomplete="on"> <h1>Log in</h1> <p> <label for="username" class="uname" data-icon="u" >Username:</label> <input id="username" name="username" required="required" type="text" placeholder="Username"/> </p> <p> <label for="password" class="youpasswd" data-icon="p">Password:</label> <input id="password" name="password" required="required" type="password" placeholder="Password" /> </p> <p class="keeplogin"> <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> <label for="loginkeeping">Keep me logged in</label> </p> <p class="login button"> <input type="submit" value="Login" /> </p> </form> 

And registration form:

 <form action="register.php" autocomplete="on"> <h1> Sign up </h1> <p> <label for="firstnamesignup" class="fname" data-icon="u">First Name:</label> <input id="firstnamesignup" name="firstnamesignup" required="required" type="text" placeholder="First" /> </p> <p> <label for="lastnamesignup" class="lname" data-icon="u">Last Name:</label> <input id="lastnamesignup" name="lastnamesignup" required="required" type="text" placeholder="Last" /> </p> <p> <label for="usernamesignup" class="uname" data-icon="u">Username:</label> <input id="usernamesignup" name="usernamesignup" required="required" type="text" placeholder="Username" /> </p> <p> <label for="passwordsignup" class="youpasswd" data-icon="p">Password:</label> <input id="passwordsignup" name="passwordsignup" required="required" type="password" placeholder="Password"/> </p> <p> <label for="passwordsignup_confirm" class="password" data-icon="p">Confirm Password:</label> <input id="passwordsignup_confirm" name="passwordsignup_confirm" required="required" type="password" placeholder="Password"/> </p> <p> <label for="emailsignup" class="youmail" data-icon="e" >Email:</label> <input id="emailsignup" name="emailsignup" required="required" type="email" placeholder=" example@domain.com "/> </p> <p> <label>Date of Birth:</label> <select name="month" onChange="changeDate(this.options[selectedIndex].value);"> <option value="na">Month</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="day" id="day"> <option value="na">Day</option> </select> <select name="year" id="year"> <option value="na">Year</option> </select> <script language="JavaScript" type="text/javascript"> function changeDate(i){ var e = document.getElementById('day'); while(e.length>0) e.remove(e.length-1); var j=-1; if(i=="na") k=0; else if(i==2) k=28; else if(i==4||i==6||i==9||i==11) k=30; else k=31; while(j++<k){ var s=document.createElement('option'); var e=document.getElementById('day'); if(j==0){ s.text="Day"; s.value="na"; try{ e.add(s,null);} catch(ex){ e.add(s);}} else{ s.text=j; s.value=j; try{ e.add(s,null);} catch(ex){ e.add(s);}}}} y = 1998; while (y-->1908){ var s = document.createElement('option'); var e = document.getElementById('year'); s.text=y; s.value=y; try{ e.add(s,null);} catch(ex){ e.add(s);}} </script> </p> <p> <label>Gender:</label> <select name="Gender"> <option value="male">Male</option> <option value="female">Female</option> </select> </p> <p class="signin button"> <input type="submit" value="Register"/> </p> </form> 

The only thing I need help with is creating / editing login.php and register.php files. Thanks for any help!

+6
source share
4 answers

You have basically a "front end" (client side), which is HTML, CSS and JS. Now you need the "back end" (server side), which is your database, SQL and PHP.

Why do you need a database?

You need a database to store user credentials during registration. You also need a database to compare the entered credentials with those that you have in your database, every time someone tries to log into the system.

What is PHP?

PHP is an open source general-purpose scripting language. Think of it like your server code. Your users do not have access to your PHP code (unlike your HTML, CSS and JS, available / accessible to everyone for viewing).

I am not going to provide you with sample code, as there are endless tutorials for it. Take a look below. Many of the following are detailed instructions on how to create / configure your database, tables, etc. Therefore, you should follow step by step and complete your project.

Hope this helps you. Good luck with your project :)

+15
source

You should add the method = "post" to the form tags. Then you can access the text fields with the variable $ _POST ['']. (In quotation marks, specify the identifier for the text field that you want to access)

As said, you should read some lessons or buy a book. I found O'Reilly's book on this subject very useful and practical.

+3
source

A form can be submitted using the $ _POST method. The submitted data is checked, that is, for registration, we must confirm that the username or email address already exists in the database. All of these checks should be done in php, i.e. server side. You can also use client side validation using javascript / jquery. You should use both of them using js / jquery validation, the validation is faster, since it works on the browser side. But javascript can be disabled from the browser, so you should also use php server side checks. Please see the examples below for the best idea.

http://forum.codecall.net/topic/44787-creating-loginregistration-forms-with-php/

http://tutorialzine.com/2009/10/cool-login-system-php-jquery/

+1
source

First add the = "post" method to the form tags. This allows the form to send submitted data to login.php and register.php.

All you have to do is write code in register.php and login.php to process the data.

If you need to with php, you must first do some basic PHP lessons. I would start with codecademy if I were you. After you finish this little course, just find your YOUTUBE tutorial.

youtube has a channel called phpacademy. They got quite a lot of clear php guides on how to create a login and login system for your page. You will learn tons from watching this, and you can write a system like yours!

Good luck

+1
source

Source: https://habr.com/ru/post/955226/


All Articles