Skip to main content
Participant
June 21, 2017
Answered

Create a password protect page in Dreamweaver CC

  • June 21, 2017
  • 4 replies
  • 10210 views

I am updating my website. One of the features the current/soon to be former site has is a page that is password protected. My web host does not have a C Panel login therefore, after researching, I believe my option is to use .htaccess. I found the .htaccess file however I am at a loss as to what to do with my page.

Any suggestions?

This topic has been closed for replies.
Correct answer osgood_

If you named the page login.php then you need to change the action attribute in the form tag -

 

From:

<form name="login" action="secure_information.php" method="post">

 

To:

<form name="login" action="login.php" method="post">

 

 

If you do that then the code should work.

 

Any protected information should be inserted after the <!--  --> (comment tags) in the code:

<!-- PROTECTED INFORMATION GOES HERE -->

 

and before

 

<?php } else { ?>

 

 

 

 

4 replies

jimg82619726
Participant
June 12, 2018

I love this and it actually works great for me, but...

I am getting an error on this line:

<?php foreach($error as $errors) {

echo "<p style='color: red;'>".$errors."</p>";

}

?>

I did not change anything but I did remove many empty lines. I am new to PHP and I am wondering why the foreach statement causes errors.

JG.

Legend
June 12, 2018

The snippet of code you posted is correct as far as my eyes can tell. Double check to make sure you have not accidentally deleted something when removing the empty lines.

What is the error message you are getting?

jimg82619726
Participant
June 12, 2018

I went back and totally copied and pasted. I added my include statement which should take me to the secured page upon entering the right information. That part works great and I love it. However, I do get this on my login screen:

Warning: Invalid argument supplied for foreach() in /home/ccwatersys/public_html/templates/secure_information.php on line 64

Line 64 is where the foreach statement is.

Jim.

John Waller
Community Expert
Community Expert
June 21, 2017

bethd9416885  wrote

I am updating my website.

What is the website address?

Do yo have a hosting plan which includes PHP? If not, what hosting plan do you have?

EPAStaffAuthor
Participant
June 21, 2017

I neglected to add that my site does not usee PHP.

Thanks.

Legend
June 21, 2017

bethd9416885  wrote

I neglected to add that my site does not usee PHP.

Thanks.

Oh well might be useful for someone else. This question is quite common in the forum.

Someone will probably be able to offer an alternative solution based on what you have available - htaccess

Legend
June 21, 2017

This can get as complicated as you like or as easy as you like. If your server can support php and you just need to protect the one page with a generic Username and Password combination then it's very easy. Example code below. You just need to change the current Username/Password combination from Bunny/Rabbit (marked in red) to that of your own choice and insert the code you want to protect where it says <!-- PROTECTED INFORMATION GOES HERE -->

Create a new completely blank DW file and name it secure_information.php - copy code and paste The login form is incorporated within the code. Its not styled, just a bare bones example of  how you would go about creating a simple protected information solution.

<?php

$username = "";

$password = "";

if(isset($_POST['submit'])) {

$username = $_POST['username'];

$password = $_POST['password'];

if($username != "Bunny") {

$error['username'] = "Wrong Username";

}

if($password != "Rabbit") {

$error['password'] = "Wrong Password";

}

}

?>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8"/>

<title>Secure Information</title>

</head>

<body>

<?php if($username == "Bunny" && $password == "Rabbit") { ?>

<h1>Welcome</h1>

<!-- PROTECTED INFORMATION GOES HERE -->

<?php } else { ?>

<h2>Login</h2>

<?php foreach($error as $errors) {

echo "<p style='color: red;'>".$errors."</p>";

}

?>

<form name="login" action="secure_information.php" method="post">

<p>

<label for="username">Username</label>

<input type="text" id="username" class="username" name="username" placeholder="Username" value="<?php if(isset($username)) { echo $username; } ?>">

</p>

<p>

<label for="password">Password</label>

<input type="text" id="password" class="password" name="password" placeholder="Password" value="<?php if(isset($password)) { echo $password; } ?>">

</p>

<p>

<input type="submit" name="submit" value="Submit">

</p>

<?php } ?>

</form>

</body>

</html>

Participant
June 28, 2024

@osgood_ I am looking to create a page within my website where members log in to view articles in a private area.   I created a php page with your code as above, I called it log in, but wasn't sure what I had to put in the protected information part as that area is greyed out and won't allow me to change it, basically I want members to be directed to a new page?   

osgood_Correct answer
Legend
June 28, 2024

If you named the page login.php then you need to change the action attribute in the form tag -

 

From:

<form name="login" action="secure_information.php" method="post">

 

To:

<form name="login" action="login.php" method="post">

 

 

If you do that then the code should work.

 

Any protected information should be inserted after the <!--  --> (comment tags) in the code:

<!-- PROTECTED INFORMATION GOES HERE -->

 

and before

 

<?php } else { ?>