By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,945 Members | 1,703 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,945 IT Pros & Developers. It's quick & easy.

redirect if https is set

P: n/a
i have the following script on my checkout page to check if https is set in
the address bar:

if ($_SERVER['HTTPS'] != "on")
{
$url = $_SERVER['SERVER_NAME'];
$query = $_SERVER['QUERY_STRING'];
$path = $_SERVER['PHP_SELF'];
header("Location: https://$url$path?$query");
}
my problem is that i need to escape from https when another page is
selected. I tried changing the code on other pages (an include file) to
read:

if ($_SERVER['HTTPS'] != "off")
{
$url = $_SERVER['SERVER_NAME'];
$query = $_SERVER['QUERY_STRING'];
$path = $_SERVER['PHP_SELF'];
header("Location: http://$url$path?$query");
}
but to no avail. Is this right?

Craig
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Craig Keightley" <do**@spam.me> wrote:
i have the following script on my checkout page to check if https is set in
the address bar:

if ($_SERVER['HTTPS'] != "on")
{
$url = $_SERVER['SERVER_NAME'];
$query = $_SERVER['QUERY_STRING'];
$path = $_SERVER['PHP_SELF'];
header("Location: https://$url$path?$query");
}
my problem is that i need to escape from https when another page is
selected. I tried changing the code on other pages (an include file) to
read:

if ($_SERVER['HTTPS'] != "off")
{
$url = $_SERVER['SERVER_NAME'];
$query = $_SERVER['QUERY_STRING'];
$path = $_SERVER['PHP_SELF'];
header("Location: http://$url$path?$query");
}

but to no avail. Is this right?


If the request is not https, the HTTPS variable will simply not exist. The
variable will NEVER equal "off".

Just use this:

if( $_SERVER['HTTPS'] == "on" )

Or, probably better:

function IsLinkSecure()
{
return isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == "on");
}

if( IsLinkSecure() )
{
...
}
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 17 '05 #2

P: n/a
Craig Keightley wrote:
i have the following script on my checkout page to check if https is set in the address bar:

if ($_SERVER['HTTPS'] != "on")


<snip>

if (!empty($_SERVER['HTTPS']))
echo 'secure';

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.