Web Education

A login system with PHP and MySQL

Many interactive web sites these days require a consumer to log in to the web site’s system. To offer custom-made expertise for the consumer. As soon as the consumer has logged in, the web site will be capable to present a presentation.

A primary login system sometimes accommodates. So, Three parts which may be created utilizing PHP and MySQL :

Part 1: Permits registration of the most popular login Id and password.

That is created in easy HTML kind that accommodates Three fields and a couple of buttons:

1. A most popular login id discipline

2. The most popular password discipline

3. The sound e mail tackle discipline

4. Submit button

5. A Reset button

The next HTML code extract is a typical instance. When the consumer has crammed in all of the fields and clicks on the submit button.

[form name=”register” method=”post” action=”register.php”]
[input name=”login id” type=”text” value=”loginid” size=”20″/][br]
[input name=”password” type=”text” value=”password” size=”20″/][br]
[input name=”email” type=”text” value=”email” size=”50″/][br]
[input type=”submit” name=”submit” value=”submit”/]
[input type=”reset” name=”reset” value=”reset”/]
[/form]

The code connects to the MySQL database. And also, inserts a line of information into the desk used to retailer the registration info.

@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Can not connect with DB!”);
@mysql_select_db(“tbl_login”) or die(“Can not choose DB!”);
$sql=”INSERT INTO login_tbl (loginid, password and e mail) VALUES (“.$loginid.”,”.$password.”,”.$e mail.”)”;
$r = mysql_query($sql);
if(!$r)
$err=mysql_error();
print $err;
exit();

The code extract assumes that the MySQL desk that’s used to retailer the registration information is called tbl_login. And also, accommodates Three fields – the loginid, password and e mail fields. The values of the $loginid, $password. And $e mail variables are handed in from the shape in register.html utilizing the submit methodology.

Part 2: Verification and authentication of the consumer.

On this the HTML kind sometimes accommodates 2 fields and a couple of buttons:

1. A login id discipline

2. A password discipline

3. A Submit button

4. A Reset button

Assume that such a kind is coded right into a file named authenticate.html. The next HTML code extract is a typical instance. When the consumer has crammed in all of the fields. So, the authenticate.php web page is known as when the consumer clicks on the Submit button.

[form name=”authenticate” method=”post” action=”authenticate.php”]
[input name=”login id” type=”text” value=”loginid” size=”20″/][br]
[input name=”password” type=”text” value=”password” size=”20″/][br]
[input type=”submit” name=”submit” value=”submit”/]
[input type=”reset” name=”reset” value=”reset”/]
[/form]

The next code extract can be utilized as a part of authenticate.php to the course of the login request. It connects to the MySQL database and queries the desk used to retailer the registration info.

@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Can not connect with DB!”);
@mysql_select_db(“tbl_login”) or die(“Can not choose DB!”);
$sql=”SELECT loginid FROM login_tbl WHERE loginid='”.$loginid.”‘ and password='”.$password.”‘”;
$r = mysql_query($sql);
if(!$r)
$err=mysql_error();
print $err;
exit();

if(mysql_affected_rows()==0)
else
print “efficiently logged into the system.”;
//proceed to carry out web site’s performance – e.g. current info to the consumer

As in part 1, the code excerpt assumes that the MySQL desk. So, that’s used to retailer the registration information is called tbl_login. And also, accommodates Three fields – the login id, password and email fields. The values of the $loginid and $password variables are handed in from the shape. In authenticate.html utilizing the submit methodology.

Part 3: When the consumer forgets his logion password this third part sends. And his password to the customers registered e mail tackle.

The HTML kind sometimes accommodates 1 discipline and a couple of buttons:

  • A login id discipline
  • The Submit button
  • A Reset button

Assume that such a kind is coded right into a file named forgot.html. The next HTML code excerpt is a typical instance. When the consumer has crammed in all of the fields.

[form name=”forgot” method=”post” action=”forgot.php”]
[input name=”login id” type=”text” value=”loginid” size=”20″/][br]
[input type=”submit” name=”submit” value=”submit”/]
[input type=”reset” name=”reset” value=”reset”/]
[/form]

The next code excerpt can be utilized as a part of forgot.php to the course of the login request. It connects to the MySQL database and queries the desk used to retailer the registration info.

@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Can not connect with DB!”);
@mysql_select_db(“tbl_login”) or die(“Can not choose DB!”);
$sql=”SELECT password, e mail FROM login_tbl WHERE loginid='”.$loginid.”‘”;
$r = mysql_query($sql);
if(!$r)
$err=mysql_error();
print $err;
exit();

if(mysql_affected_rows()==0)
else

As in part 1, the code excerpt assumes that the MySQL desk. So, that’s used to retailer the registration information is called tbl_login. And also, accommodates Three fields – the login id, password and email fields. The software program developer can embrace extra instruments like password encryption. So, entry to the consumer profile in case they want to edit their profile and so forth.

Compiled of those parts.

This text has been compiled by the content material growth crew at Pegasus InfoCorp. So, which pulls material specialists from completely different work domains. They are often contacted by way of the Pegasus InfoCorp web site at information@pegasusinfocorp.com. Pegasus InfoCorp is an India based mostly internet design, internet growth, and on-line/offline software program growth firm. Please go to http://www.pegasusinfocorp.com to learn extra articles and know extra about us!

Different corporations and organizations

Different corporations and organizations are welcome to reprint. So, this text on their web sites offered the next circumstances are met.

  • The article just isn’t modified in any method
  • The article is copied as is in its entirety . (together with one-way links to the Pegasus InfoCorp web site).
  • The corporate/ group reprinting the article agrees to defend, indemnify and maintain innocent Pegasus InfoCorp, its workers, administrators, officers, brokers, companions, and their successors and assigns from and towards any and all liabilities, damages, losses, prices, and bills, together with legal professional’s charges, attributable to or arising out of claims based mostly upon using the article, together with any declare of libel, defamation, violation of rights of privateness or publicity, lack of service by subscribers and infringement of mental property or different rights

Comment here