Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
  • Advertise
  • About
  • Contact Us

PHP Password protected Web Page

September 11, 2020 Pakainfo php, Ajax, JavaScript, jQuery, Laravel, Mysql Leave a comment

in php password protected page, secure Password protect your data content with Web Page Password Protect by just including single line of PHP source code to your web page source. full source code will present user with secure password entry form, and will not let any type of the visitor see your private all the data content without accessing a secure password.

Create Password Protected Webpage Using PHP, HTML And CSS

Contents

  • Create Password Protected Webpage Using PHP, HTML And CSS
    • Step 1. Create a PHP file and define markup
    • Step 2. Create a CSS file and define styling
  • Easy way to password-protect php page
    • Related posts

Bellow simple Example to learn step by step Free PHP Scripts :: Web Page Password Protect.

Also Read : Password Protecting Website running on NGinx serve PHP-FPM

Step 1. Create a PHP file and define markup

I simply Create a PHP file as well save it with a name password.php

<?php
session_start();

if(isset($_POST['submit_pass']) && $_POST['pass'])
{
 $pass=$_POST['pass'];
 if($pass=="98256")
 {
  $_SESSION['password']=$pass;
 }
 else
 {
  $error="sorry dear, your Incorrect Pssword";
 }
}

if(isset($_POST['home_sign_out']))
{
 unset($_SESSION['password']);
}
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="password_style.css">
</head>
<body>
<div id="wrapper">

<?php
if($_SESSION['password']=="98256")
{
 ?>
 <h1>Create Password Protected Webpage Using PHP, HTML And CSS - www.pakainfo.com</h1>
 <form method="post" action="" id="logout_form">
  <input type="submit" name="home_sign_out" value="LOGOUT">
 </form>
 <?php
}
else
{
 ?>
 <form method="post" action="" id="signin_frm">
  <h1>Sign In TO PROCEED</h1>
  <input type="password" name="pass" placeholder="************">
  <input type="submit" name="submit_pass" value="DO SUBMIT">
  <p>"Password : 98256"</p>
  <p><font style="color:red;"><?php echo $error;?></font></p>
 </form>
 <?php	
}
?>

</div>
</body>
</html>

In this phase i first of all check if user sign in or not by verifyed then session variable if the user is not sign in i will show signin form and if user is sign in i showing webpage data content with sign out button.i use main two isset() condition to do signin or sign out.In simple main condition i simply read the user password as well as check if the set of the password is ‘98256’ if yes i update the password in session variable using php as well as then show the webpage.In onther condition i simply unset the session variable using php which stores/saved password value.You may also such as a simple http secure authentication using PHP source code.

Also Read This πŸ‘‰   How to Count Number of Files in directory PHP?

Step 2. Create a CSS file and define styling

i create a CSS file and save it with a name password_style.css

body
{
 margin:0 auto;
 padding:0px;
 text-align:center;
 width:100%;
 font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;
 background-color:#8A4B08;
}
#wrapper
{
 margin:0 auto;
 padding:0px;
 text-align:center;
 width:995px;
}
#wrapper h1
{
 margin-top:50px;
 font-size:45px;
 color:white;
}
#wrapper p
{
 font-size:16px;
}
#logout_form input[type="submit"]
{
 width:250px;
 margin-top:10px;
 height:40px;
 font-size:16px;
 background:none;
 border:2px solid white;
 color:white;
}
#signin_frm
{
 margin-top:200px;
 background-color:white;
 width:350px;
 margin-left:310px;
 padding:20px;
 box-sizing:border-box;
 box-shadow:0px 0px 10px 0px #3B240B;
}
#signin_frm h1
{
 margin:0px;
 font-size:25px;
 color:#8A4B08;
}
#signin_frm input[type="password"]
{
 width:250px;
 margin-top:10px;
 height:40px;
 padding-left:10px;
 font-size:16px;
}
#signin_frm input[type="submit"]
{
 width:250px;
 margin-top:10px;
 height:40px;
 font-size:16px;
 background-color:#8A4B08;
 border:none;
 box-shadow:0px 4px 0px 0px #61380B;
 color:white;
 border-radius:3px;
}
#signin_frm p
{
 margin:0px;
 margin-top:15px;
 color:#8A4B08;
 font-size:17px;
 font-weight:bold;
}

Easy way to password-protect php page

in this way simply you can Create two files:

  • protect-this.php
  • login.php:
Also Read This πŸ‘‰   check if all values in array are true javascript

protect-this.php

<?php
    $password = '[email protected]';

    if (empty($_COOKIE['password']) || $_COOKIE['password'] !== $password) {
        header('Location: login.php');
        exit;
    }
?>

login.php:

<?php
    $password = '[email protected]';

    $redirect_after_login = 'index.php';
    $remember_password = strtotime('+30 days'); // 30 days

    if (isset($_POST['password']) && $_POST['password'] == $password) {
        setcookie("password", $password, $remember_password);
        header('Location: ' . $redirect_after_login);
        exit;
    }
?>
<!DOCTYPE html>
<html>
<head>
    <title>Password protected - www.pakainfo.com</title>
</head>
<body>
    <div style="text-align:center;margin-top:50px;">
        You must enter the password to view this content.
        <form method="POST">
            <input type="text" name="password">
        </form>
    </div>
</body>
</html>

Note: Then you can simply need to protect-this.php on the TOP of the main files you want to protect:
Password protect this content

require_once('protect-this.php');

Free Live Chat for Any Issue

I hope you get an idea about php password protected page.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Pakainfo
Pakainfo

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Also Read This πŸ‘‰   PHP MySQLi RESTful API with Slim Framework

Related posts:

  1. Reset Password Form Free bootstrap Widget Template
  2. how to make a login page in html with database?
  3. Multiple image slider in html source code
  4. html code for login page with username and password validation
  5. Validate Email Password Using jQuery
  6. Laravel 5.6 Like Dislike rating system with jQuery, Ajax and PHP
  7. How To Create Image Hover Overlay Effects?
  8. Send Forgot password by mail or message in PHP
  9. how to delete data from database in php using button?
  10. how to show error messages below the textbox in javascript validation?
create password protected file in phpjquery password protect pagepassword protect html pagepassword protect website php/mysqlphp password filephp password protect page _sessionphp password protect page multiple usersphp simple password login

Post navigation

Previous Post:how to add edit and delete rows of a html table with javascript?
Next Post:How to Create html to pdf using php | Convert HTML to PDF using PHP

Search

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (56) Ajax (464) AngularJS (377) ASP.NET (61) Bollywood (100) Codeigniter (175) CSS (98) Earn Money (61) Education (56) Entertainment (121) fullform (82) Google Adsense (62) Highcharts (77) Hollywood (101) JavaScript (1356) Jobs (40) jQuery (1422) Laravel (1087) LifeStyle (51) movierulz4 (55) Mysql (1029) Mysqli (890) Node.js (39) php (2117) Programming (2330) Python (96) ReactJS (37) Software (134) Software (83) Stories (94) tamilrockers (96) Tamilrockers kannada (56) Tamilrockers telugu (55) Tech (132) Technology (2377) Tips and Tricks (113) Tools (168) Top10 (388) Trading (69) Trending (63) VueJs (250) Web Technology (93) webtools (173) wordpress (166) World (209)

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here

  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2022 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype YouTube Tag Extractor