Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

test secure connection

Posted on 2005-03-03
5
Medium Priority
?
338 Views
Last Modified: 2008-03-10
is there a way with php to check if the page is being viewed on a secure connection?

e.g. https vs http

thanks
0
Comment
Question by:qwertq
  • 4
5 Comments
 
LVL 11

Accepted Solution

by:
matt_mcswain earned 500 total points
ID: 13450027
One way:

if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on'))
0
 

Author Comment

by:qwertq
ID: 13450091
great!

and i assume i can use (below) accordingly.
(!isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] != 'on'))

where do you get $_SERVER['HTTPS'] from? i do not see it reflected in the manual http://us2.php.net/reserved.variables
0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13450147
It a webserver variable. I believe it's a mod_ssl thing.
So your best bet is to create a phpinfo() page and view it using https, to make sure you have it.
0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13450175
Oh, and if you're doing your test that way, don't require both conditions; so

(!isset($_SERVER['HTTPS']) || ($_SERVER['HTTPS'] != 'on'))
0
 
LVL 11

Expert Comment

by:matt_mcswain
ID: 13450249
Funny enough, it is documented on the link you posted; in the contributed comments anyway. :)
Scroll down about three-quarters down the page or do a search for "https".
There's also another solution posted-->$_SERVER['SERVER_PORT']==443
But really just check your phpinfo().
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question