1

I'm making a page as follows, There will be a menu for on the left. In the menu there will be links home, page1, page2, page3 and pageProtected. When I click on any page, this menu will remain unchanged. Only the content of the page on the right will change.

I made a file "left.php" and content of each page as "page1Content.php" etc.

When I click on page1, it takes me to page1.php, which includes left.php and page1Content.php.

Html code...
<?php include("left.php")?>
more html code...
<?php include("page1Content.php")?>

So in each file, only the second included file changes. All the html code are identical for all pages. But I have a protected page, which needs a login window. It is called "pageProtected.php". The thing is I want to keep this file in the main folder, but keep the content: "pageProtectedContent.php" in a folder where I put the .htaccess file.

However when I do this, it doesn't ask password. And when I put "pageProtected.php" in this folder, I have to change "left.php" that I include in this file. Then my purpose of keeping a unique "left.php" is not satisfied. What are my options?

Probably this is a very novice question, but I couldn't find a solution in the internet. Note: I don't want to use frames for the left menu.

1 Answer 1

1

.htaccess files only prevent the files from being accessed in a web browser, PHP can include files in htaccess protected folders as if they weren't protected.

I think what you need to do is have pageProtectedContent.php check for a cookie or use php sessions to facilitate login and authentication.

If it is included and the user is not logged in, it will display a login form, if they are logged in, then it will display the protected content.

The only other way to use .htaccess would be to put the protected pages in the protected folder, but you would then need to change your include statements to use ../left.php etc.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.