Protect a Website Part Using PHP?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

Program:- Protect a Website Part Using PHP? You want to use PHP protect parts of your website with passwords. Instead of storing the passwords in an external file and letting the web server handle the authentication, you want the password verification logic to be in a php Program.

Solution – Protect a Website Part Using PHP

<?php
function user_check($user, $pass){
	$users = array('hindi'=>'alerts');
	if (isset($users[$user])&& ($users[$user]===$pass)) {
		return 1;
	}else{
		return 0;
	}
}
if (!user_check($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])){
	http_response_code(401);
	header('WWW-Authenticate: Basic Realm="My Own website"');
	echo "You need to enter valid username & password ";
	exit();

}else{
	echo 'Logged In';
}
?>

इसे भी पढ़े – Photoshop Convert Point और Rectangle Tool

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *