+1 vote
11 views

I'm working on a shopping cart website and I would like to redirect the user to a HTTPS page when he's entering his billing details and maintain the HTTPS connection for the next pages until he logs out.

What do I need to install on the server (I'm using Apache) in order to do this, and how can this redirect be done from PHP?

by (1.4k points)   | 11 views

1 Answer

+1 vote

Try this to do so

<?php
if (!(isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || 
   $_SERVER['HTTPS'] == 1) ||  
   isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&   
   $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'))
{
   $redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
   header('HTTP/1.1 301 Moved Permanently');
   header('Location: ' . $redirect);
   exit();
}
?>
by (3.3k points)  
Thanks! You saved my time!

Related questions

+3 votes
1 answer
asked Mar 30 by toheed (1.4k points) | 27 views
+1 vote
1 answer
+2 votes
1 answer
+2 votes
0 answers
+4 votes
1 answer
asked Mar 29 by admin (1.3k points) | 46 views
+4 votes
1 answer
asked Mar 20 by Ron | 47 views
+1 vote
1 answer
+2 votes
0 answers
asked Jun 20 by athar (3.3k points) | 16 views




Welcome to Meansflow - Where Developers and Students Learn, Share, & Build Careers, where you can ask questions and receive answers from other members of the community.
118 questions
90 answers
43 comments
110 users