如何创建注册/登录。php文件为我的网站?

时间:2022-11-23 13:20:08

I am trying to make a website that allows for a register form as well as a login form. I have all the HTML and CSS setup but I need php to handle the form. I need it to be validated too.

我正在尝试建立一个网站,允许注册表单和登录表单。我有所有的HTML和CSS设置,但我需要php来处理表单。我也需要验证一下。

Below 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 the regsister form:

和regsister形式:

<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 the login.php and register.php files. Thanks for any help!

我唯一需要帮助的是创建/编辑登录。php和登记。php文件。感谢任何帮助!

4 个解决方案

#1


16  

What you have is basically the 'front end' (client side) which is the HTML,CSS and JS. Now you need the 'back end' (server side) which is your Database, SQL and PHP.

你所拥有的基本上就是“前端”(客户端),即HTML、CSS和JS。现在需要“后端”(服务器端),即数据库、SQL和PHP。

Why do you need a Database?

为什么需要数据库?

You need a database to store your user credentials when they register. Also you need the DB to compare the entered credentials with the ones you have in your DB every time someone tries to login.

当用户注册时,您需要一个数据库来存储用户凭证。此外,您还需要DB来比较每次有人尝试登录时输入的凭据与数据库中的凭据。

What is PHP?

PHP是什么?

PHP is an open source general-purpose scripting language. Think of it like your server-side code. Your users don't have access to your PHP code (unlike your HTML,CSS and JS which is accessible/available to everyone to view).

PHP是一种开源的通用脚本语言。把它想象成服务器端代码。您的用户没有访问PHP代码的权限(不像HTML、CSS和JS,每个人都可以访问/可用)。

I am not going to provide you with sample code as there are infinite tutorials for that.Have a look on some below. A lot of the below have detailed instructions on how to create/setup your Database, tables etc so it is up to you to follow step by step and complete your project.

我不会给你们提供样本代码,因为有无数的教程。看看下面的一些。下面有很多关于如何创建/设置您的数据库、表等的详细说明,因此您可以一步一步地完成您的项目。

  1. http://www.phpeasystep.com/phptu/6.html
  2. http://www.phpeasystep.com/phptu/6.html
  3. http://php.about.com/od/finishedphp1/ss/php_login_code.htm
  4. http://php.about.com/od/finishedphp1/ss/php_login_code.htm
  5. http://www.wikihow.com/Create-a-Basic-Login-Script-in-PHP
  6. http://www.wikihow.com/Create-a-Basic-Login-Script-in-PHP
  7. http://www.homeandlearn.co.uk/php/php14p2.html
  8. http://www.homeandlearn.co.uk/php/php14p2.html
  9. http://phpsnips.com/4/Simple-User-Login#.Uk41QYZmi-0
  10. http://phpsnips.com/4/Simple-User-Login .Uk41QYZmi-0
  11. http://www.html-form-guide.com/php-form/php-login-form.html
  12. http://www.html-form-guide.com/php-form/php-login-form.html

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

希望这能帮助你。祝你的项目好运:)

#2


3  

You should append method="post" to your form tags. Then you can access the text fields with the variable $_POST['']. (In the quotes place the identifier for the text field you'd like to access)

您应该将方法="post"附加到窗体标签上。然后可以使用变量$_POST["]访问文本字段。(在引号中输入您想要访问的文本字段的标识符)

Like was stated you should read some tutorials or buy a book. I found O'Reilly's book on the subject very helpful and practical.

如前所述,你应该阅读一些教程或买一本书。我发现奥莱利关于这个主题的书非常有用和实用。

#3


1  

The form can be submitted using the $_POST method. The submitted data is checked ie for registration we have to verify the username or email already exist in the database . All these validations must be done in php ie the server side validation. You can also use client side validation with javascript/jquery. You must use both of them by using js/jquery validation the validations runs faster as it runs on the browser side. But javascript can be disabled from the browser so you must use php server side validations as well. Please check out the below examples by which you will get a better idea.

可以使用$_POST方法提交表单。提交的数据被检查ie为注册,我们必须验证用户名或电子邮件已经存在于数据库中。所有这些验证都必须在php ie服务器端验证中完成。您还可以使用javascript/jquery的客户端验证。您必须使用它们,通过使用js/jquery验证,验证在浏览器端运行时运行得更快。但是可以在浏览器中禁用javascript,因此必须使用php服务器端验证。请看看下面的例子,从中你会得到一个更好的主意。

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

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

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

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

#4


1  

First add method="post" to the form tags. This makes the form able to send the data filled in send to the login.php and register.php.

首先向表单标签添加方法=“post”。这使得表单能够将填写的数据发送到登录。php和register.php。

All you need to do now is to write the code in register.php and login.php to handle to form data.

现在需要做的就是在register中编写代码。php和登录。用于处理形成数据的php。

If you're need with php you should first do some basic PHP tutorials. I would start at codecademy if i were you. After you finish that little course, just look up a tutorial on YOUTUBE.

如果需要使用php,您应该首先做一些基本的php教程。如果我是你,我会从codecademy开始。完成这个小课程后,在YOUTUBE上查找教程。

on youtube there is a channel called "phpacademy". They got quite a few very clear php tutorials on how to make a register and login system for your page. You'll learn tons from watching that, and you'll be able to write a system like that your own!

在youtube上有一个叫做“phpacademy”的频道。关于如何为您的页面创建注册和登录系统,他们有很多非常清晰的php教程。你会从观察中学习到很多东西,你也可以自己编写一个系统!

Good luck!

好运!

#1


16  

What you have is basically the 'front end' (client side) which is the HTML,CSS and JS. Now you need the 'back end' (server side) which is your Database, SQL and PHP.

你所拥有的基本上就是“前端”(客户端),即HTML、CSS和JS。现在需要“后端”(服务器端),即数据库、SQL和PHP。

Why do you need a Database?

为什么需要数据库?

You need a database to store your user credentials when they register. Also you need the DB to compare the entered credentials with the ones you have in your DB every time someone tries to login.

当用户注册时,您需要一个数据库来存储用户凭证。此外,您还需要DB来比较每次有人尝试登录时输入的凭据与数据库中的凭据。

What is PHP?

PHP是什么?

PHP is an open source general-purpose scripting language. Think of it like your server-side code. Your users don't have access to your PHP code (unlike your HTML,CSS and JS which is accessible/available to everyone to view).

PHP是一种开源的通用脚本语言。把它想象成服务器端代码。您的用户没有访问PHP代码的权限(不像HTML、CSS和JS,每个人都可以访问/可用)。

I am not going to provide you with sample code as there are infinite tutorials for that.Have a look on some below. A lot of the below have detailed instructions on how to create/setup your Database, tables etc so it is up to you to follow step by step and complete your project.

我不会给你们提供样本代码,因为有无数的教程。看看下面的一些。下面有很多关于如何创建/设置您的数据库、表等的详细说明,因此您可以一步一步地完成您的项目。

  1. http://www.phpeasystep.com/phptu/6.html
  2. http://www.phpeasystep.com/phptu/6.html
  3. http://php.about.com/od/finishedphp1/ss/php_login_code.htm
  4. http://php.about.com/od/finishedphp1/ss/php_login_code.htm
  5. http://www.wikihow.com/Create-a-Basic-Login-Script-in-PHP
  6. http://www.wikihow.com/Create-a-Basic-Login-Script-in-PHP
  7. http://www.homeandlearn.co.uk/php/php14p2.html
  8. http://www.homeandlearn.co.uk/php/php14p2.html
  9. http://phpsnips.com/4/Simple-User-Login#.Uk41QYZmi-0
  10. http://phpsnips.com/4/Simple-User-Login .Uk41QYZmi-0
  11. http://www.html-form-guide.com/php-form/php-login-form.html
  12. http://www.html-form-guide.com/php-form/php-login-form.html

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

希望这能帮助你。祝你的项目好运:)

#2


3  

You should append method="post" to your form tags. Then you can access the text fields with the variable $_POST['']. (In the quotes place the identifier for the text field you'd like to access)

您应该将方法="post"附加到窗体标签上。然后可以使用变量$_POST["]访问文本字段。(在引号中输入您想要访问的文本字段的标识符)

Like was stated you should read some tutorials or buy a book. I found O'Reilly's book on the subject very helpful and practical.

如前所述,你应该阅读一些教程或买一本书。我发现奥莱利关于这个主题的书非常有用和实用。

#3


1  

The form can be submitted using the $_POST method. The submitted data is checked ie for registration we have to verify the username or email already exist in the database . All these validations must be done in php ie the server side validation. You can also use client side validation with javascript/jquery. You must use both of them by using js/jquery validation the validations runs faster as it runs on the browser side. But javascript can be disabled from the browser so you must use php server side validations as well. Please check out the below examples by which you will get a better idea.

可以使用$_POST方法提交表单。提交的数据被检查ie为注册,我们必须验证用户名或电子邮件已经存在于数据库中。所有这些验证都必须在php ie服务器端验证中完成。您还可以使用javascript/jquery的客户端验证。您必须使用它们,通过使用js/jquery验证,验证在浏览器端运行时运行得更快。但是可以在浏览器中禁用javascript,因此必须使用php服务器端验证。请看看下面的例子,从中你会得到一个更好的主意。

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

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

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

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

#4


1  

First add method="post" to the form tags. This makes the form able to send the data filled in send to the login.php and register.php.

首先向表单标签添加方法=“post”。这使得表单能够将填写的数据发送到登录。php和register.php。

All you need to do now is to write the code in register.php and login.php to handle to form data.

现在需要做的就是在register中编写代码。php和登录。用于处理形成数据的php。

If you're need with php you should first do some basic PHP tutorials. I would start at codecademy if i were you. After you finish that little course, just look up a tutorial on YOUTUBE.

如果需要使用php,您应该首先做一些基本的php教程。如果我是你,我会从codecademy开始。完成这个小课程后,在YOUTUBE上查找教程。

on youtube there is a channel called "phpacademy". They got quite a few very clear php tutorials on how to make a register and login system for your page. You'll learn tons from watching that, and you'll be able to write a system like that your own!

在youtube上有一个叫做“phpacademy”的频道。关于如何为您的页面创建注册和登录系统,他们有很多非常清晰的php教程。你会从观察中学习到很多东西,你也可以自己编写一个系统!

Good luck!

好运!