[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 480
  • Last Modified:

PHP Authentication not logging in on different server.

Hi!

I use this authentication-script with success on my own server. Now i want to use this script on a different server and i can't login anymore. I get this error message in chrome:

The webpage at http://example.com/cms/ might be temporarily down or it may have moved permanently to a new web address.
Error 15 (net::ERR_SOCKET_NOT_CONNECTED): Unknown error.\

If i remove the script from the page, i can access it.

So what could be causing it not to work?

Thanks for the help!
<?

//Site username
define ("USERN", "admin");
//Site password
define ("PASSW", "pass");

if(isset($_GET['logout'])){
	unset($_SESSION["realm"]);
	header("HTTP/1.0 401 Unauthorized");
	session_destroy() ;
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://example.com/cms/logout/\" />";
	exit;
}
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || !isset($_SESSION['realm'])) {
	$_SESSION['realm'] = mt_rand( 1, 10000 );
	header("WWW-Authenticate: Basic realm=".$_SESSION['realm']);
	header("HTTP/1.0 401 Unauthorized");
	$_SESSION["realm"] = true;
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://example.com/cms/logout-wrong/\" />";
	exit;
}else{
  if($_SERVER['PHP_AUTH_USER'] == USERN && $_SERVER['PHP_AUTH_PW'] == PASSW){
	echo "<h1>".SITETITLE." - CMS</h1>";
	echo "<p>Je bent ingelogd als: <b>".USERN."</b> [<a href='http://example.com/cms/index.php?logout'  class=\"menu\">Logout</a>]";
	echo " OF: Sluit de browser om uit te loggen. [<a href='http://example.com/cms/index.php' target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
	echo "<hr width=\"" .HRWIDTH. "\" align=\"left\" color=\"#FF00FF\">";
  }else{
    unset($_SESSION["realm"]);
    session_destroy() ;
    header("Location: " . "http://example.com/cms/");
  exit;
  }
}
?>

Open in new window

0
peps03
Asked:
peps03
  • 3
1 Solution
 
peps03Author Commented:
i think this could be a valueweb issue. because this is where the site is hosted.
also other authentication scripts i tried on their servers won't login.

what could cause this issue?
0
 
Ray PaseurCommented:
Interesting but inscrutable.  Please have a look at this article and see if it has some ideas that might be helpful:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0
 
peps03Author Commented:
This worked for me for some reason:

I added this in .htaccess. (Change test.php to your script name)

RewriteEngine on
RewriteCond %{HTTP:Authorization} !^$
RewriteRule^test.php$ test.php?login=%{HTTP:Authorization}


And then in my PHP script, i added the following, right before my user/pass check routine:

$d = base64_decode(substr($_GET['login'],6) );
list($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']) = explode(':', $d);
0
 
peps03Author Commented:
it worked for this to.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now