PHP Authentication not logging in on different server.

Posted on 2011-05-07
Last Modified: 2012-05-11

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 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");

	header("HTTP/1.0 401 Unauthorized");
	session_destroy() ;
	echo "<meta http-equiv=\"refresh\" content=\"0;URL=\" />";
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=\" />";
	echo "<h1>".SITETITLE." - CMS</h1>";
	echo "<p>Je bent ingelogd als: <b>".USERN."</b> [<a href=''  class=\"menu\">Logout</a>]";
	echo " OF: Sluit de browser om uit te loggen. [<a href='' target=\"_self\" class=\"menu\">Terug naar het overzicht</a>]</p>";
	echo "<hr width=\"" .HRWIDTH. "\" align=\"left\" color=\"#FF00FF\">";
    session_destroy() ;
    header("Location: " . "");

Open in new window

Question by:peps03

    Author Comment

    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?
    LVL 107

    Expert Comment

    by:Ray Paseur
    Interesting but inscrutable.  Please have a look at this article and see if it has some ideas that might be helpful:

    Accepted Solution

    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);

    Author Closing Comment

    it worked for this to.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    This is a general how to create your own custom plugin system for your PHP application that you designed (or wish to extend a third party program to have plugin functionality that doesn't have it yet).  This is not how to make plugins for existing s…
    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now