I\'ve got just one page that I want to force to be accessed as an HTTPS page (PHP on Apache). How do I do this without making the whole directory require HTTPS? Or, if you s
Ok.. Now there is tons of stuff on this now but no one really completes the "Secure" question. For me it is rediculous to use something that is insecure.
Unless you use it as bait.
$_SERVER propagation can be changed at the will of someone who knows how.
Also as Sazzad Tushar Khan and the thebigjc stated you can also use httaccess to do this and there are a lot of answers here containing it.
Just add:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
to the end of what you have in your .httaccess and thats that.
Still we are not as secure as we possibly can be with these 2 tools.
The rest is simple. If there are missing attributes ie...
if(empty($_SERVER["HTTPS"])){ // SOMETHING IS FISHY
}
if(strstr($_SERVER['HTTP_HOST'],"mywebsite.com") === FALSE){// Something is FISHY
}
Also say you have updated your httaccess file and you check:
if($_SERVER["HTTPS"] !== "on"){// Something is fishy
}
There are a lot more variables you can check ie..
HOST_URI (If there are static atributes about it to check)
HTTP_USER_AGENT (Same session different values)
So all Im saying is dont just settle for one or the other when the answer lies in a combination.
For more httaccess rewriting info see the docs-> http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Some Stacks here -> Force SSL/https using .htaccess and mod_rewrite
and
Getting the full URL of the current page (PHP)
to name a couple.