Creating a Sign Up and Log In Page
Creating a Sign Up and Log In Page
Outline: Creating a Sign Up and Log In Page
In this tutorial, we’ll be running our PHP scripts and MySQL database server on a local web server called XAMPP.
Creating Our Database and Table
Open your phpMyAdmin i.e. http://localhost/phpmyadmin and create a new database named logindb.
The following 5 columns should be created to input: id, user_id, user_name, password, date;
- id, user_id are indicated as BIGINT under Type.
- user_name, password are indicated as VARCHAR under Type.
- date is indicated as TIMESTAMP under Type.
- corresponding to id – NULL index, PRIMARY, tick AI (autoincrement)
- Press Go to save.
- Click More and Add Index each for user_id, user_name, date.
Creating Our Database Connection
Launch your chosen text editor, such as Sublime Text 3, Notepad ++, or another. Create a new connection.php file and place it in the xampp/htdocs/login folder. Into this PHP file, copy and paste the following codes, then save.
Creating Our Interfaces
The codes for the pages in our sign-up and login web applications are contained in the PHP File scripts shown below. Using the recommended filenames for each, save the files under the folder xampp/htdocs/login.
Create index.php
Create and save a new PHP file with the name index.php, then copy and paste the scripts below:
Ron Website
Logout
This is the index page
Hello,
Creating login.php
Create and save another PHP file called login.php, and then copy and paste the following scripts:
0)
{
$user_data = mysqli_fetch_assoc($result);
if($user_data['password'] === $password)
{
$_SESSION['user_id'] = $user_data['user_id'];
header("Location: index.php");
die;
}
}
}
echo "wrong username or password!";
}else
{
echo "wrong username or password!";
}
}
?>
Login
Creating signup.php
Make a new PHP file called signup.php and copy and paste the following scripts:
Signup
Creating functions.php
Copy and paste the following scripts into a new PHP file called functions.php that you create and save.
0)
{
$user_data = mysqli_fetch_assoc($result);
return $user_data;
}
}
//redirect to login
header("Location: login.php");
die;
}
function random_num($length)
{
$text = "";
if($length < 5)
{
$length = 5;
}
$len = rand(4,$length);
for ($i=0; $i < $len; $i++) {
# code...
$text .= rand(0,9);
}
return $text;
}
Creating logout.php
Create and save a new PHP file called logout.php, then copy and paste the scripts below: