1

I have a breadcrumb script and its displaying an error:

"Notice: Undefined index: HTTPS in ... on line ..."

The code line is:

$base = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';

How can I solve this?

  • http://php.net/manual/en/reserved.variables.php --- http://php.net/manual/en/reserved.variables.server.php --- http://stackoverflow.com/questions/1175096/how-to-find-out-if-youre-using-https-without-serverhttps – Funk Forty Niner Mar 17 '17 at 18:40
  • Well was the script queried through HTTPS? if not then https wouldn't be defined. – Tony Mar 17 '17 at 18:40

1 Answers1

2

Check for the existence of the HTTPS key first using isset:

$base = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';

In this particular case you only need to check existence so it would be safe to simplify it to:

$base = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156