Languages :: PHP :: Https fails on client systems |
|||
| By: omuyelijah |
Date: 18/10/2008 15:29:24 |
Points: 20 | Status: Answered Quality : Excellent |
|
Hi All, I've created a certificate and installed it in apache/conf/ssl folder. On my server PC (my laptop), I can enforce a page to be accessed securedly through the code snippet below <?php //this code appears at the top of html page b4 raw html appears if ($_SERVER[] != 443) { $sec_page='https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; header("Location: $sec_page "); //problematic line } ?> This code works well on my server, but on client PCs on my LAN (where server is my laptop), the code fails. The aim is that access to a web application from client pcs would be through a secured page. Why does it fail? have tried several code changes and have come 2 see that the problem is somewhere around the commented 'problematic line', and likely has to do with $_SERVER['HTTP_HOST'] On server, it resolves to 'localhost' but it think this is why it fails. Will check the logs 2 see more information. Any comments and help ? Thanks in advance. |
|||
| By: WebMentor | Date: 19/10/2008 21:46:14 | Type : Comment |
|
| try using $_SERVER['SERVER_ADDR'] instead of $_SERVER['HTTP_HOST'] | |||
| By: VGR | Date: 20/10/2008 07:39:27 | Type : Comment |
|
| heoo, I suppose it's SERVER_PORT in your first line about 443 ? ;-) try this kind of stuff : <?php $https_url = 'https://therighturl.tld'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] == 'off' ) { header('location: ' . $https_url); exit; } else if ( !isset( $_SERVER['HTTPS']) && $_SERVER['SERVER_PORT'] == 443 ) { header('location: ' . $https_url); exit; } ?> or simply if ($_SERVER["SERVER_PORT"] != 443) { header('Location: https://www.example.com'); exit; } You may alternatively use mod_rewrite or .htaccess RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [L,R] Do you have any errors in error.log, on screen, in the browser's error console, in HTML page source ? |
|||
| By: omuyelijah | Date: 10/12/2008 16:21:41 | Type : Answer |
|
| Hi All, First, thanks for your suggestions. I checked the logs but found no error/report related to the mentioned failure. All of the above suggestions I'm sure will work. Well, I overcame the problem as follows: 1. Recreated the SSL certificate using the IP address of server for the COMMON NAME field; 2. Edited httpd.conf file, creating a new virtualhost section for the IP, ensuring that the SSLCertificateFile and SSLCertificateKeyFile are set, pointing to the correct location of certificate and key files on the server. <VirtualHost xxx.xxx.xxx.xxx:443> SSLEngine On SSLCertificateFile conf/ssl/exam-server.der SSLCertificateKeyFile conf/ssl/exam-server.key </VirtualHost> I'm coming to see that if it were 2 be hosted, resolution will solve the issue, i.e. resolving domain name to IP but for the LAN, this worked. |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








