Protect a Website Part Using PHP?

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

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

	echo 'Logged In';


Be the first to comment

Leave a Reply

Your email address will not be published.