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.

Nancy OShea
Community Expert
Community Expert
June 21, 2017

Your site may not use PHP currently but your server probably supports it.   Most Linux servers do.   If not, you have a very strange hosting plan.

If you use the .htaccess and .htpasswd method, you'll need to create  a new directory on your server. 

Password Protection with htaccess - Htaccess Tools

NOTE:  If you're on a Windows server, contact your hosting provider to help you.

Nancy O'Shea— Product User & Community Expert
John Waller
Community Expert
Community Expert
June 22, 2017

https://forums.adobe.com/people/John+Waller  wrote

I always thought the existence of .htaccess = Apache server = PHP

.htaccess is available in Apache if configured through Apache to do so. PHP module would need to be installed on the Apache server in order for the server to support php. That's why LAMP stack is separate installations of Linux, Apache, MySQL, and PHP. They are separate entities that are combined to create a stack.

Apache installed on the server does not automatically mean that php is installed also. You have to specifically install the correct version of php module on the server and then restart the server in order for Apache to support php. In order words: just because you put peanut butter on a slice of bread does not mean that another slice of bread with jelly on it is automatically available. You need to put jelly on another slice of bread and put it together with the slice of bread that has peanut butter on it in order to have a PBJ sandwich.


EbaySeller  wrote

Apache installed on the server does not automatically mean that php is installed also.

Yes, of course.

It's just that whenever a client has been uncertain of their hosting plan's inclusions, every time I have found a .htaccess file it's an Apache server with PHP installed too.

In this case, mention of .htaccess but no Control Panel suggests a very basic hosting plan on a PHP/Apache server. Their site may not use PHP but it's available on the server with an upgraded hosting plan.

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 { ?>