1. Run SQL script below in MySQL to create users table to :
CREATE TABLE `users` ( `id` INT UNSIGNED NOT NULL
AUTO_INCREMENT PRIMARY KEY ,
`username` VARCHAR( 20 ) NOT NULL ,
`password` VARCHAR( 20 ) NOT NULL ) ENGINE = MYISAM;
2. Create connect.php to connect to database
<?php
session_start();
//use @ to ignore warning message
@mysql_connect('localhost', 'root', 'mypassword') or die("Unable to Connect to the MySQL Database at this time");;
@mysql_select_db('userlogin') or die("Unable to Select the MySQL Database at this time");
?>
3. Create newsession.php to keep login active for a while
<?php
$_SESSION['id']=session_id();
$_SESSION['userid']=$r_username;
?>
4. create logincheck.php
<?php
include "connect.php";
if(isset($_REQUEST['submit']))
{
$r_username = @mysql_real_escape_string($_REQUEST['username']);
$r_password = @mysql_real_escape_string($_REQUEST['password']);
$query = @mysql_query("SELECT * FROM `users`
WHERE `username` = '".$r_username."'
AND `password` = '".$r_password."'");
if(@mysql_num_rows($query) > 0)
{
include "newsession.php" }
else {
session_unset();
echo "Use your correct UserName and Password and Try";
}
?>
5. Final login.php
<?php
session_start();
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Login Page</title>
</head>
<form action='logincheck.php' method=post>
UserName
<input type ='text' name='username' ><br>
password
<input type ='password' name='password' > <br>
<input type="submit" name="submit" value="Login" /> <input type='reset' value='Reset'>
</form>
<a href='signup.php'>New Member Sign UP</a>
</body>
</html>
The display of the results after modification can be found Here
Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- How to blend adsense inside your post?
- Formatting my post
- Notepad++ - Add C++ compiler
- Install PHPMailer 5.2.4 and use smtp gmail
- Set up a child account and set screen time limit in Windows 8
- Wayback Machine - see archived versions of web pages across time
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHP ibm_db2 extension in Linux (redHat)
- PHP: add a download as pdf file button in report page
No comments:
Post a Comment