Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-10-2004, 03:19 AM   #1
Registered: Sep 2004
Posts: 223

Rep: Reputation: 30
how to check if the visitor is using https using php ?


I am building an ecommerce order page using https .
I am worried because someone could call the pages using http instead of https.

How to check if the visitor is really using https using php or javascript (and automatically redirect him to the same page using https) ?

Thank you
Old 11-10-2004, 03:54 AM   #2
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
The best way IMHO is to declare https virtual host in a separate directory then the one for the http
virtual host, of course if you don't have access to httpd.conf, it is another story...

You could use something like :
PHP Code:
if( $_SERVER["SERVER_PORT"] != 443 ) {
$url "https://".$_SERVER["HTTP_HOST"]."/".$_SERVER["REQUEST_URI"];
header("Location: $url");

Last edited by Cedrik; 11-10-2004 at 03:56 AM.
Old 11-10-2004, 10:10 AM   #3
Registered: Sep 2004
Posts: 223

Original Poster
Rep: Reputation: 30
thanks a lot !
Old 11-10-2004, 02:55 PM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
A slightly different way:
PHP Code:
if ($_SERVER['HTTPS']!="on") {
$url "https://".$_SERVER["HTTP_HOST"]."/".$_SERVER["REQUEST_URI"];
header("Location: $url");

Last edited by Hko; 11-10-2004 at 03:02 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I check if PHP is installed? imsam Linux - Newbie 8 02-13-2012 02:51 PM
Check if URL is SSL or not in PHP michaelsanford Programming 3 04-14-2010 07:34 AM
php/mysql check varchar() xushi Programming 13 07-15-2005 11:20 AM
Visitor tracking in Perl SiLiCoN Programming 3 04-11-2005 10:36 AM
Visitor Based Networks Mux General 0 12-04-2002 08:10 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:47 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration