Experts Exchange connects you with the people and services you need so you can get back to work.
Improve company productivity with a Business Account.Sign Up
Your question, your audience. Choose who sees your identity—and your question—with question security.
<?php // RAY_https_only.php
// DEMONSTRATE HOW TO RESTRICT A SCRIPT SO THAT IT ONLY RUNS BEHIND HTTPS
// IF NOT HTTPS
// CONSTRUCT THE HTTPS URL WE WANT, PRESERVING GET VARS
// BAIL OUT WITH 301 AND LOCATION
header("HTTP/1.1 301 Moved Permanently");
// ELSE WE ARE ALREADY IN HTTPS - START SESSION FOR HTTPS ONLY IN ALL SUBDIRECTORIES AND ALL SUBDOMAINS
$x = explode('.', strtolower($_SERVER["HTTP_HOST"]));
$y = count($x);
if ($y == 1) // MAYBE 'localhost'?
$cookie_domain = $x;
else // SOMETHING LIKE 'www2.atf70.whitehouse.gov'?
// USE THE LAST TWO POSITIONS TO MAKE THE HOST DOMAIN
$cookie_domain = '.' . $x[$y-2] . '.' . $x[$y-1];
$sess_name = session_name();
// MAN PAGE: http://us2.php.net/manual/en/function.setcookie.php
setcookie($sess_name, session_id(), NULL, '/', $cookie_domain, TRUE, TRUE);
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.
One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.