force the user to utilize https

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
soshea
Forum Commoner
Posts: 31
Joined: Tue Nov 12, 2002 11:22 pm
Location: Idaho
Contact:

force the user to utilize https

Post by soshea »

been reading the docs and prior messages in the forum but have not found the answer yet.
is there a way to force the user to utilize https i.e. something at the top of the page to say if not https then exit. i am making a login script but have noticed that the users are capable of accessin the pages i want encrypted with http and https.
any ideas? i looked at the mod_ssl page and only got more confused on the httpd.conf modification.
thanx for any advice!!
sean
User avatar
soshea
Forum Commoner
Posts: 31
Joined: Tue Nov 12, 2002 11:22 pm
Location: Idaho
Contact:

found it

Post by soshea »

exactly what i was looking for

Code: Select all

<?php
if ($_SERVER['HTTPS'] !== 'on') {
die("Must be a secure connections");
}
?>

?>
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Hey mate this might just solve some of my problems. Thank you for this small code.
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post by pistolfire99 »

Hey mate this might just solve some of my problems. Thank you for this small code. Also is there any way you can send them to another page if they are not using https.

Thank You.
User avatar
soshea
Forum Commoner
Posts: 31
Joined: Tue Nov 12, 2002 11:22 pm
Location: Idaho
Contact:

Post by soshea »

you will want to use header()

Code: Select all

<?php
header('location: http//www.yourpagehere.com');
exit();
?>
but you may also want to inform them of why they were redirected away.

http://www.php.net/manual/en/function.header.php

later
soshea
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

I've been using the SERVER_PORT to check for this, but I like your way much better. Anyone know if this works for IIS or just Apache? I don't have a Windows test server right now.
User avatar
soshea
Forum Commoner
Posts: 31
Joined: Tue Nov 12, 2002 11:22 pm
Location: Idaho
Contact:

Post by soshea »

doing this on linux-apache no idea about IIS.
soshea
Post Reply