Jump to content

Http Authenication


barkster

Recommended Posts

I was using this small script to prompt for password on some password protected folders.  It was working great but I've moved servers and now the script hangs on the line "if(defined('USER_AUTHENTICATED') && USER_AUTHENTICATED){"  It doesn't like the "USER_AUTHENTICATED" but if I take it out it shows the page while it is prompting for password which I don't want.  What could be causing this, is USER_AUTHENTICATED a global variable or something?  Not quite sure.  Thanks

 

	require_once 'http_authenticate.php';		
	if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
		// this simply means that they have submitted the login form for this realm
		$htpasswd = "Gallery/".$row['UserID']."/".$row['Folder']."/.htpasswd";
		$auth=http_authenticate($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'],$htpasswd);
		define('USER_AUTHENTICATED',$auth);
	}

	if(defined('USER_AUTHENTICATED') && USER_AUTHENTICATED){
		// authentication successful - show the content
		echo '<?xml version="1.0" encoding="iso-8859-1"?>',"\n";
	} else {
		// the user has not been authenticated, present a login form.
		header('WWW-Authenticate: Basic realm="'.$row['Folder'].'"');
		header('HTTP/1.0 401 Unauthorized');
		// if cancel the login form, below is what they get
		exit('Authentication is required to view this page.');
	}

Link to comment
https://forums.phpfreaks.com/topic/64573-http-authenication/
Share on other sites

Don't know it is part of a script that I was using from here http://koivi.com/php-http-auth/

 

it used to work on my old server and now it just hangs after you put in the username/password  If I take out && USER_AUTHENTICATED and just put if(defined('USER_AUTHENTICATED')){  It shows the page content when it prompts for the username/password.  With it in there on my old server it does not show the content until successful authentication.

 

Link to comment
https://forums.phpfreaks.com/topic/64573-http-authenication/#findComment-321965
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.