Jump to content

PHP page lock, put password to enter page.


izildop

Recommended Posts

Hello I'm beginner with php, but I have a good question.

 

I have a html page with a navigationbar, let's say I click on my navbar about me, just for example.

How can I lock the screen with a password before someone can start clicking or scrolling in the about me page.

So only the one with the password can enter that single page that is locked.

 

Doing this with javascript is not good because you can open the web codes and see what the password is.

How do I do this in PHP, anyone can help?

Link to comment
Share on other sites

Pretty simple: use a form to post a password to the page, then only show the page if the right password was sent.

 

Basically,

<!-- header of your page, up until the content area -->
<?php if (!isset($_POST["password"]) || $_POST["password"] != "yourpasswordhere") { // no password or wrong password ?>
<form action="" method="post">
<p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p>
</form>
<?php } else { // correct password ?>
<!-- normal page content -->
<?php } ?>
<!-- footer of your page -->
Every time they visit the page they have to enter the password. It won't "remember" them.
Link to comment
Share on other sites

Pretty simple: use a form to post a password to the page, then only show the page if the right password was sent.

 

Basically,

<!-- header of your page, up until the content area -->
<?php if (!isset($_POST["password"]) || $_POST["password"] != "yourpasswordhere") { // no password or wrong password ?>
<form action="" method="post">
<p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p>
</form>
<?php } else { // correct password ?>
<!-- normal page content -->
<?php } ?>
<!-- footer of your page -->
Every time they visit the page they have to enter the password. It won't "remember" them.

 

<!doctype html>
<html>

<head> 
	<title> Basisschool De Regenboog </title>
			<style>
img {
	position: absolute;
	left: 60%;
}
			</style>
</head>
	<body>
<a href="http:/www.youtube.com"><img src="Plaatjes/youtube.png" />
			
		<script>

		</script>	
<!-- header of your page, up until the content area -->
<?php if (!isset($_POST["password"]) || $_POST["password"] != "123") { // no password or wrong password ?>
<form action="" method="post">
<p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p>
</form>
<?php } else { // correct password ?>
<!-- normal page content -->
<?php } ?>
<!-- footer of your page -->
	</body>
</html>

I put a youtube button link on the page, but when I click to write down the password it directly send me to youtube, and it shouldn't show the button or atleast only unlock the page when you put the pass in.

Mabey I misunderstood something (just a beginner)

Link to comment
Share on other sites

The contents of the page your want to "password protect" need to go where this line is  <!-- normal page content -->, Example

<html>

<head> 
	<title> Basisschool De Regenboog </title>
			<style>
img {
	position: absolute;
	left: 60%;
}
			</style>
</head>
	<body>
			
		<script>

		</script>	
<!-- header of your page, up until the content area -->
<?php if (!isset($_POST["password"]) || $_POST["password"] != "123") { // no password or wrong password ?>
<form action="" method="post">
<p>Password: <input type="password" name="password"> <button type="submit">Enter</button></p>
</form>
<?php } else { // correct password ?>
<!-- normal page content -->
<a href="http:/www.youtube.com"><img src="Plaatjes/youtube.png" /></a>
<?php } ?>
<!-- footer of your page -->
	</body>
</html>

If the user has not submitted the correct password then the login form will show. Only until the user has entered the correct password (currently 123) then the youtube link will display.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.