PhilTilson Posted January 19, 2007 Share Posted January 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/34925-login-works-in-localhost-but-not-on-host-server/ Share on other sites More sharing options...
printf Posted January 19, 2007 Share Posted January 19, 2007 I don't see how it would work if the user is not authorized. Because you can't send a header after you output content! <!DOCTYPE...>Unless you use the ob_ functions.printf Quote Link to comment https://forums.phpfreaks.com/topic/34925-login-works-in-localhost-but-not-on-host-server/#findComment-164692 Share on other sites More sharing options...
PhilTilson Posted January 19, 2007 Author Share Posted January 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/34925-login-works-in-localhost-but-not-on-host-server/#findComment-164702 Share on other sites More sharing options...
knightcon_2004 Posted January 19, 2007 Share Posted January 19, 2007 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 Link to comment https://forums.phpfreaks.com/topic/34925-login-works-in-localhost-but-not-on-host-server/#findComment-164746 Share on other sites More sharing options...
printf Posted January 20, 2007 Share Posted January 20, 2007 post a link to your PHP info file on your ISP server. So I can see what PHP is running as![code]<?phpinfo():?>[/code]printf Quote Link to comment https://forums.phpfreaks.com/topic/34925-login-works-in-localhost-but-not-on-host-server/#findComment-164760 Share on other sites More sharing options...
PhilTilson Posted January 20, 2007 Author Share Posted January 20, 2007 [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 Quote Link to comment https://forums.phpfreaks.com/topic/34925-login-works-in-localhost-but-not-on-host-server/#findComment-164984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.