Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,154 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,365 people online right now. Registration is fast and FREE... Join Now!




Redirection to Secure Site

 
Reply to this topicStart new topic

Redirection to Secure Site

noobiez
22 Aug, 2008 - 08:39 AM
Post #1

New D.I.C Head
*

Joined: 20 Aug, 2008
Posts: 18

Hi Guys,

Noobiez here again. I need help. Currently, i have a form that resides on my server which i would like users to only be able to access it VIA SSl and nothing else. So the question is. How do i write a redirect script which is able to check if it is accessed via SSL and to reject non-SSL connection. I know i can redirect using header but to check for SSL connections. I'm clueless. Thanks fer all help!

Rgrds,
Noobiez.
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Redirection To Secure Site
22 Aug, 2008 - 11:27 AM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
php
if($_SERVER['SERVER_PORT'] != '443') {

//Force SSL upon this page

header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);

}


=P
User is offlineProfile CardPM
+Quote Post

noobiez
RE: Redirection To Secure Site
22 Aug, 2008 - 11:51 PM
Post #3

New D.I.C Head
*

Joined: 20 Aug, 2008
Posts: 18

QUOTE(JBrace1990 @ 22 Aug, 2008 - 12:27 PM) *

php
if($_SERVER['SERVER_PORT'] != '443') {

//Force SSL upon this page

header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);

}


=P

Hi mate,

I've got this error instead...
QUOTE
Warning: Cannot modify header information - headers already sent by (output started at /home/twcadm/public_html/reg/acct.php:7) in /home/twcadm/public_html/reg/acct.php on line 11


Rgrds,
Noobiez.
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Redirection To Secure Site
23 Aug, 2008 - 11:00 AM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 479



Thanked: 24 times
Dream Kudos: 350
My Contributions
that's because headers need to be sent before ANY text is sent.... put that up at the very top of the page before you echo anything (so add it right after session_start() if you have it)
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:36AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month