6 月 052013
 

原文(source): .htaccess – How do I force HTTPS on a single file? (PHP) – Stack Overflow

At the beginning of the PHP page that does all your credit card processing, you can add this:

It will redirect back to itself, except using https if it was first loaded over http. Of course you still need an SSL certificate installed for your domain.

if(!isset($_SERVER['HTTPS'])||!$_SERVER['HTTPS']){// if request is not secure, redirect to secure url
    $url ='https://'. $_SERVER['HTTP_HOST']. $_SERVER['REQUEST_URI'];
    header('Location: '. $url);
    exit;
}