Kathyweller Designs

Just sharing the experience of information about the online world
Friday, July 10, 2009

An access system with PHP and MySQL

Web Design

Many websites now require that the user logs on to the system to provide the experience of individual users. Once the user is registered, the site will be capable of providing, personal user preferences.

Access system generally contains 3 basic components that can be created using PHP and MySQL:

Component 1: Allows the recording and preferred username password.

This creates a simple HTML form which contains 3 field and 2 buttons:

1. Your preferred username field

2. Sexual Preference

3. E-mail address field

4. A button

5. Reset Button

Let’s talk about the coded form in a file called register.html. The following HTML code excerpt is a typical example. By completing all fields and click “Send” button, the page requires register.php.

[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 following extract of code can also be used as part of register.php to register. Code connects to the MySQL database and inserts a row in the table for storing information on the record.

@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Cannot connect to DB!”);
@mysql_select_db(“tbl_login”) or die(“Cannot select DB!”);
$sql=”INSERT INTO login_tbl (loginid, password and email) VALUES (“.$loginid.”,”.$password.”,”.$email.”)”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}

Extract of code that indicates the MySQL table that is used for storing log data is called tbl_login and contains 3 fields – in login, password and email address fields. Log-in $ values, $ email and $ password variables passed as register.html using the method of entry.

Component 2: verification and user authentication.

This HTML form contains 2 fields, 2 buttons:

1. An access zone

2. In the password field

3. A button

4. Reset Button

I guess that is a coded form in a file called authenticate.html. The following HTML code excerpt is a typical example. By completing all fields, and then authenticate.php page is called when a user clicks “Send” 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 following extract of code can be used as part of authenticate.php at the entrance of the application. Connects to the MySQL database and queries the table used to store registration data.

@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Cannot connect to DB!”);
@mysql_select_db(“tbl_login”) or die(“Cannot select 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){
print “no such login in the system. please try again.”;
exit();
}
else{
print “successfully logged into system.”;
//proceed to perform website’s functionality – e.g. present information to the user
}

As in component 1, the code assumes that the extract in the MySQL table that is used for storing log data is called tbl_login and contains 3 fields – in login, password and email address fields. The values of $ $ login and password variables passed in the way authenticate.html using the method of entry.

Component 3: when the user forgets his password logion this component 3 sends the password to registered users, e-mail addresses.

HTML form typically contains 1 field and 2 buttons:

• In the Login
• A button
• Reset button

I guess that is a coded form in a file called forgot.html. The following HTML code snippet is a typical example. By completing all fields, and then forgot.php page is called when a user clicks “Send” button.

[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]

Below is a snippet of code can be used as part of forgot.php at the entrance of the application. Connects to the MySQL database and queries the table used to store registration data.

@mysql_connect(“localhost”, “mysql_login”, “mysql_pwd”) or die(“Cannot connect to DB!”);
@mysql_select_db(“tbl_login”) or die(“Cannot select DB!”);
$sql=”SELECT password, email FROM login_tbl WHERE loginid=’”.$loginid.”‘”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print “no such login in the system. please try again.”;
exit();
}
else {
$row=mysql_fetch_array($r);
$password=$row["password"];
$email=$row["email"];

$subject=”your password”;
$header=”from:you@yourdomain.com”;
$content=”your password is “.$password;
mail($email, $subject, $row, $header);

print “An email containing the password has been sent to you”;
}

As in component 1, the code assumes that the extract in the MySQL table that is used for storing log data is called tbl_login and contains 3 fields – in login, password and email address fields. The cost of $ login variable is changed from the way forgot.html using the method of entry.

Thus, the main entrance, the system can be created. Software developer may include additional tools such as encryption, passwords, access to user profile, if you want to change your profile etc.

This document has been prepared in accordance with the development team at Pegasus INFOCORP pulling in experts from various fields of activity. They may be contacted through the site info@pegasusinfocorp.com INFOCORP Pegasus. INFOCORP Pegasus is the India based web design, web development and online / offline software development company. Please visit http://www.pegasusinfocorp.com read more articles and learn more about us!

Other companies and organizations have to reprint this article on your website provided the following conditions are met.
? The article is not altered in any way
? The article is copied as a whole (including links back to your site Pegasus INFOCORP).
? The company / organization reprinting the article agrees to defend, and hold harmless Pegasus INFOCORP, its officers, directors, employees, agents, partners and their successors and assigns, and against all liabilities, damages, costs and expenses, including attorney’s fees, caused by or arising out of claims based on the implementation of this article, including any claim for defamation, libel, violation of rights of privacy or publicity, loss of service subscribers and violation of intellectual property rights or other rights

  • Share/Bookmark
Options

Comment Form