Hello, Today's tutorial is based on How To Make Registration And Login System In PHP!
PHP is one of the most finest languages.
So for this tutorial you'll have to learn the basics of PHP!
So, before starting you have to make sure that you have PHP and MySQL installed on your computer.
If you don't have then I'll suggest you to download XAMPP.
For that just go on google and type xampp and click on the first link and then download it.
So Let's Get Started
We'll have to make 3 files for this tutorial and they'll be index.php, home.php and logout.php
Index.php
<html>
<head><title>Log In And Register</title>
</head>
<body>
<form method="post">
<h3>Log In : </h3><BR>
<?php
session_start();
if (isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];
mysql_connect("localhost" , "root" , "");
mysql_select_db("users");
$check_query = mysql_query("SELECT * FROM users WHERE email='$email'AND password='".md5($password)."'");
if (mysql_num_rows($check_query) == 1) {
while ($row = mysql_fetch_assoc($check_query)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$dbemail = $row['email'];
$dbpassword = $row['dbpassword'];
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
}
if ($email == $dbemail && $password == $dbpassword) {
header("location:home.php");
} else {
echo "<B>The Password That You Entered Was Incorrect</B><BR><BR>";
}
} else {
echo "<B>That User Doesn't Exist</B><BR><BR>";
}
}
?>
<input type="text" name="email" placeholder="Email" required></input>
<input type="password" name="password" placeholder="Password" required </input><BR><BR>
<input type="submit" name="submit" value="Log In">
</form>
<h3>Sign Up : </h3><BR>
<form method="post">
<?php
if (isset($_POST['submit_reg'])) {
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["reg_email"];
$password = $_POST["reg_password"];
mysql_connect("localhost" , "root" , "");
mysql_select_db("users");
$insert_query = mysql_query("INSERT INTO users VALUES ('' , '".$firstname."' , '".$lastname."' , '".$email."' , '".md5($password)."')");
header("location:home.php");
}
?>
<input type="text" name="firstname" placeholder="First Name"></input>
<input type="text" name="lastname" placeholder="Last Name"></input>
<BR>
<input type="text" name="reg_email" placeholder="Email"></input>
<input type="password" name="reg_password" placeholder="Password"></input><BR>
<input type="submit" name="submit_reg" value="Sign Up">
</form>
</body>
</html>
Home.php
<html>
<head><title>Home</title>
</head>
<body>
<?php
session_start();
if (isset($_SESSION['firstname'] && $_SESSION['lastname']) && !empty($_SESSION["firstname"] && $_SESSION["lastname"])) {
return true;
} else {
return false;
}
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
?>
<h3><?php echo "Welcome, " . $firstname . " " . $lastname; ?></h3>
<BR>
<a href="logout.php">Log Out</a>
</body>
</html>
Logout.php
<?php
if (isset($_SESSION['firstname'] && $_SESSION['lastname']) && !empty($_SESSION["firstname"] && $_SESSION["lastname"])) {
return true;
} else {
return false;
}
session_destroy();
header("location:index.php");
?>
So That Was It.
Happy Programming
Follow Me On My Facebook Accout
PHP is one of the most finest languages.
So for this tutorial you'll have to learn the basics of PHP!
So, before starting you have to make sure that you have PHP and MySQL installed on your computer.
If you don't have then I'll suggest you to download XAMPP.
For that just go on google and type xampp and click on the first link and then download it.
So Let's Get Started
We'll have to make 3 files for this tutorial and they'll be index.php, home.php and logout.php
Index.php
<html>
<head><title>Log In And Register</title>
</head>
<body>
<form method="post">
<h3>Log In : </h3><BR>
<?php
session_start();
if (isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];
mysql_connect("localhost" , "root" , "");
mysql_select_db("users");
$check_query = mysql_query("SELECT * FROM users WHERE email='$email'AND password='".md5($password)."'");
if (mysql_num_rows($check_query) == 1) {
while ($row = mysql_fetch_assoc($check_query)) {
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$dbemail = $row['email'];
$dbpassword = $row['dbpassword'];
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
}
if ($email == $dbemail && $password == $dbpassword) {
header("location:home.php");
} else {
echo "<B>The Password That You Entered Was Incorrect</B><BR><BR>";
}
} else {
echo "<B>That User Doesn't Exist</B><BR><BR>";
}
}
?>
<input type="text" name="email" placeholder="Email" required></input>
<input type="password" name="password" placeholder="Password" required </input><BR><BR>
<input type="submit" name="submit" value="Log In">
</form>
<h3>Sign Up : </h3><BR>
<form method="post">
<?php
if (isset($_POST['submit_reg'])) {
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["reg_email"];
$password = $_POST["reg_password"];
mysql_connect("localhost" , "root" , "");
mysql_select_db("users");
$insert_query = mysql_query("INSERT INTO users VALUES ('' , '".$firstname."' , '".$lastname."' , '".$email."' , '".md5($password)."')");
header("location:home.php");
}
?>
<input type="text" name="firstname" placeholder="First Name"></input>
<input type="text" name="lastname" placeholder="Last Name"></input>
<BR>
<input type="text" name="reg_email" placeholder="Email"></input>
<input type="password" name="reg_password" placeholder="Password"></input><BR>
<input type="submit" name="submit_reg" value="Sign Up">
</form>
</body>
</html>
Home.php
<html>
<head><title>Home</title>
</head>
<body>
<?php
session_start();
if (isset($_SESSION['firstname'] && $_SESSION['lastname']) && !empty($_SESSION["firstname"] && $_SESSION["lastname"])) {
return true;
} else {
return false;
}
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
?>
<h3><?php echo "Welcome, " . $firstname . " " . $lastname; ?></h3>
<BR>
<a href="logout.php">Log Out</a>
</body>
</html>
Logout.php
<?php
if (isset($_SESSION['firstname'] && $_SESSION['lastname']) && !empty($_SESSION["firstname"] && $_SESSION["lastname"])) {
return true;
} else {
return false;
}
session_destroy();
header("location:index.php");
?>
So That Was It.
Happy Programming
Follow Me On My Facebook Accout
No comments:
Post a Comment