Jump to content

Recommended Posts

Hi - have a problem with some simple login code that works fine when I run it on my localhost server, but fails when I upload it to my ISP's server.  (Please don't criticise the very basic security - there's a reason!).  Code is as follows:

[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
//An array of allowed users and their passwords
include 'UserDtls.php';

//If there's no authentication header, exit
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="CCPAdmin"');
exit('This page requires authentication');
}

//If the username doesn't exist, exit
if(!isset($users[$_SERVER['PHP_AUTH_USER']])) {
header('HTTP/1.1 401 Unauthorised');
header('WWW-Authenticate: Basic realm="CCPAdmin"');
exit('You are not authorised to view this page!');
}

//If the password doesn't match correctly, exit
if($users[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW']) {
header('HTTP/1.1 401 Unauthorised');
header('WWW-Authenticate: Basic realm="CCPAdmin"');
exit('You are not authorised to view this page!');
}
?>

[/code]

On localhost, everything works perfectly; on ISP server, I always get the first error message - "This page requires authentication".

I've checked the sticky on HEADERS etc but I don't think that's it.  Any ideas, please?  The [b]include[/b] file is just an array declaration with username/password pairs - but I don't get that far!

Phil
Sorry - fairly new to this.  Thought I'd caught that one, but didn't realise that the <!DOCTYPE...> line sent output to the browser!

I now get the login box but it refuses to accept any of the username/password pairs I have in the array.  Again, this works fine on my localhost.

Can you solve this one too?!

Phil
some firewall configurations prevent outgoing data such as what you get when you enter your user information into a http authentication box. I have the same problem at school, the firewall blocks the authentication stream. There are two work arounds that I have used...

[list]
[*]Have your network administrator add the websites address as authorised to send data in both ways
[*]Use a html login form rather than a http authentication box
[/list]

Give that a try, it should work.
[quote]post a link to your PHP info file on your ISP server. So I can see what PHP is running as![/quote]

Check out [url=http://www.tptp.co.uk/checkphp.php]http://www.tptp.co.uk/checkphp.php[/url] - could it be something to do with the fact that my local installation is running the Apache 2.0 handler as the server API while my ISP is running CGI?

Phil
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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