Error message from HTTPS check

I’m getting an error message from a piece of code in a Drupal site I’ve been working on.

function getAddress()
 {
    /*** check for https ***/
    $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
    /*** return the full address ***/
    //return             
    //$protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 }
 
 $redirectURL = "http://www.example.com/menu";
 $oneURL = "www.example.com/one/menu"; 
 $twoURL = "www.example.com/two/menu";
 $threeURL = "www.example.com/three/menu";
 $fourURL = "www.example.com/four/menu";
 $fiveURL = "www.example.com/five/menu";
 $sixURL = "www.example.com/six/menu";
 
 if(getAddress()==$oneURL || getAddress()==$twoURL || getAddress()==$threeURL || getAddress()==$fourURL || getAddress()==$fiveURL || getAddress()==$sixURL)
 {
	header('Location:'.$redirectURL);
 }
 

//echo getAddress();

I didn’t write this code. I’m just coming into this site. From what I can figure, it checks for whether the website is requested through http or https and rewrites accordingly. But I’m not sure as I’m still very wet behind the ears with PHP.

Anyway, these are the errors that I get from this code

I get this 6 times.
Notice: Undefined index: HTTPS in /home/example/public_html/index.php on line 19

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/example/public_html/index.php:19) in /home/example/public_html/includes/bootstrap.inc on line 1031

This is for lines 630 thru 633
Warning: Cannot modify header information - headers already sent by (output started at /home/example/public_html/index.php:19) in /home/example/public_html/includes/bootstrap.inc on line 630

I know that this code is involved with all of these errors because when I comment it out they all go away. Anyone have any idea of what in this code is creating these errors? Or even specifically what the code does and how vital it is?

Hello NT_cookies,

I believe that because there are not https any url’s that you provide for function getAddress, the value $_SERVER[‘HTTPS’] doesn’t exist, so you receive

Notice: Undefined index: HTTPS in /home/example/public_html/index.php on line 19

The other errors come as you already sent the headers.

I wondered about that. Only thing is that this is a clone site on a different url. The original site generates the same errors as this, but https is available on it and not on the clone site because I haven’t gotten an SSL Certificate for it.