+1 vote
46 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)   | 46 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, 2020 by toheed (1.4k points) | 37 views
+1 vote
1 answer
+2 votes
1 answer
asked May 3, 2020 by Antonio | 68 views
+2 votes
0 answers
+4 votes
1 answer
asked Mar 29, 2020 by admin (1.4k points) | 57 views
+4 votes
1 answer
asked Mar 20, 2020 by Ron | 55 views
+1 vote
1 answer
asked May 26, 2020 by toheed (1.4k points) | 21 views
+2 votes
0 answers
asked Jun 20, 2020 by athar (3.3k points) | 26 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.
122 questions
92 answers
43 comments
124 users