4

I just discovered that I have thousands of these errors, coming from two of the same files.

I have removed a lot of errors by using the isset, but I can´t figure out how to remove the last two errors. Maybe you guys can help me.

PHP Notice:  Undefined index: HTTPS on /xxx/xxx/xxx.php on line 123

Code from the first PHP file that generates the error:

function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}

More exactly this line:

if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

And

if (isset($tag)) {
$tag = htmlspecialchars($_REQUEST['tag'], ENT_QUOTES);
}
2by
  • 1,083
  • 5
  • 22
  • 39
  • Why can't you use isset there, too? – andrewsi Jun 20 '13 at 16:32
  • I´ve tried setting $tag to NULL if its not set, but it does not help – 2by Jun 20 '13 at 16:37
  • Where are you initially setting `$tag`? The if statement you've included is checking to see if it's already set, then assigning a value to it - do you maybe mean to do `if (isset($_REQUEST['tag']))` ? – andrewsi Jun 20 '13 at 16:39

1 Answers1

19

You can change:

if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

to:

if (array_key_exists('HTTPS', $_SERVER) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

array_key_exists returns a boolean. Since I check it first and use && the if statement will exit before checking the value of $_SERVER["HTTPS"] if it doesn't exist.