Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dpalme

macrumors newbie
Original poster
Dec 20, 2009
25
0
All of a sudden I am having a problem with a script that has worked for a long time. The only change was I moved everything to a new server.....

Here is the error message:

Code:
Notice: Use of undefined constant HTTP_HOST - assumed 'HTTP_HOST' in /usr/home/dougpalme/www/data/galleries/login.php on line 251

Here is a copy of the login.php program:
Code:
<?php
/*
 Filename:	login.php
 
 		It can be renamed to whatever, just make sure to set
 		the variable "loginScript" in settings.js correctly!
 
 Author:	Peter Berger, www.peterberger.at
 		for www.EOS4you.com
 Last change:   2007-03-04 
 
 Description:	Server side gallery protection script. Asks for password
                and sets a cookie if correct. See also passwords.php
                  
*/

// general settings
$masterPassword		= "NoneYaBusiness";			// allows access to all galleries!
$caseSensitivePW	= 1;			// 1 = case sensitive, 0 = not
$styleFile              = "eoscommon/black2.css";
/* $styleFile		= "eoscommon/style.css";
*/
$dirIsPW		= 0;			// 0 = use password.php file
						// 1 = folder name is password

// text parts
$pageTitle	= "Login page";
$enterPW	= "Please enter the password:";
$submitPW	= "Submit Password";
$hintPW		= "";	// delete the next line if no hint should be shown
$hintPW		= "Du Quoin Cutting Password is: cutting (Lower Case).";
$wrongPW	= "The password is not correct, please try again.";
$wrongGal	= "The gallery is not available. Please contact the photographer.";
$enterGal	= "You need enter the gallery name to proceed:";
$noteCase	= "Note that the password is case sensitve!";
$accessOK	= "Access granted!";
// end of settings

function print_header($title) {
	global $styleFile;
	$html = "html";
	echo <<< END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<$html>
<head>
	<TITLE>Timeless Equine Photography</TITLE>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/>
	<meta name="description" content="Equestrian Photography. The passion of capturing the unique bond between horse and rider. Portrait, Endurance, Cutting, Farm Call, Senior and pet photography by Douglas W. Palme, Central Illinois, Eastern Missouri and Southeastern Iowa.  Regular appearances in the Springfield, Peoria, Bloomington and Champaign, IL areas.">
	<meta name="keywords" content="equestrian, horse, performance horse, quarter horse, equine photography, stallion, poney club, arabian, appaloosa, paint horse, pintos, miniature horse, friesian, paxton farm, Greenstone stables, Trails End stable, horse portraits, sport, Dayton,lebanon, Wainesville, Springfield, Springboro, pictures, sport horse, eventing, endurance, dressage, reining, hunter jumper, roping, cutting, pleasure, halter, images, photographs, Peter DeMott, professional equine photography, illinois, springfield, chatham, peoria, rockford, chicago, missouri, iowa, wisconsin, bloomington, champaign">
	<meta name="author" content="Douglas W. Palme"/> 
	<META name="Copyright" content="Copyright Timeless Equine Photography">
	<META http-equiv="Content-Language" content="en">
	<META name="rating" content="Photography">
<link type="text/css" rel="stylesheet" href="$styleFile">
<style type="text/css">
<!--
.error {
	margin-top: 20px;
	margin-bottom: 20px;
	padding: 15px;
	background-color: #ffffff;
	color: #000000;
	border: 2px solid #000000;
	font-size: 14px;
	font-weight: bold;
	display: block;
	width: 500px;
}
.access {
	margin-top: 20px;
	margin-bottom: 20px;
	padding: 15px;
	background-color: #ffffff;
	color: darkgreen;
	border: 2px solid darkgreen;
	font-size: 14px;
	font-weight: bold;
	display: block;
	width: 500px;
}
-->
</style>
</head>
<body>
<!-- insert your HTML header code below (logo, link to homepage, e.t.c.) -->

<br><br><br><br>
<center>
END;
}

function checkPW($pw, $pwstring, $caseSens) {
	global $masterPassword;
	if($pw == $masterPassword) return 1;
	
	if($caseSens == 0) {
		$pw	  = strtolower($pw);
		$pwstring = strtolower($pwstring);
	}
	// convert delimiters
	$pwstring = str_replace(",", ";", $pwstring);
	$pwstring = str_replace(":", ";", $pwstring);
	$pwarr = explode(";", $pwstring);
	foreach ($pwarr as $val) {
		if($val == $pw) return 1;
	}
	return 0;
}

function get_relativePath ($p1) {
	$p2 = $_SERVER["PHP_SELF"];
	// p1: /galleries/2008/eventxx
	// p2: /galleries/login.php
	// -> return:     2008/eventxx 
	$lastSlash = 0;
	for($i=0; $i < strlen($p1); $i++) {
		if($p1[$i] == "/") $lastSlash = $i;
		if($p1[$i] != $p2[$i]) {
			$ret = substr($p1, $lastSlash+1);
			$ret = str_replace("\\'", "'", $ret);	// \'  -->  '
			return $ret;
		}
	}
}

function make_absolutePath($dir) {
	if(strpos($dir, "/") === 0 || strpos(strtolower($dir), "http://") === 0)
		return $dir;	// already absolute
	// else
	$adir = dirname($_SERVER["PHP_SELF"]) . "/" . $dir;
	$adir = str_replace("//", "/", $adir);	// --> /
	return $adir;
}

function show_error($msg) {
	echo "<span class=\"error\">$msg</span><br>\n";
}

function input_password($title, $hint) {
	global $hidden_fields, $submitPW;
	echo <<< END
<FORM name="f" method="POST">
$title
<input type="password" name="passw">
$hidden_fields
<input type="submit" value="$submitPW">
<br><br>
<span class="hint">$hint</span>
</form>
END;
}

function input_galleryname($title, $pw) {
	global $hidden_fields;
	echo <<< END
<FORM name="f" method="POST">
$title
<input type="text"   name="gallery">
<input type="hidden" name="passw" value="$pw">
$hidden_fields
<input type="submit">
</form>
END;
}

function print_fwd($title, $path) {
	global $hidden_fields;

	echo "<span class=\"access\">$title</span><br>\n";	
	if($hidden_fields != "")
		echo <<< END
<FORM name="f" method="GET" action="$path/">
$hidden_fields
</form>
<script type="text/javascript">
setTimeout('document.forms[0].submit()', 1000)
</script>
END;

	else 
		echo <<< END
<script type="text/javascript">
function fwd() {location.replace("$path")}
setTimeout('fwd()', 1000)
</script>
END;

	echo <<< END
	
<noscript>
<a href="http://www.eos4you.com/home/enablejs.html">Please enable JavaScript</a> to view this gallery.
</noscript>
END;
}

function fwd2gallery($path, $domain) {
	global $accessOK;
	$path = urlencode($path);
	$path = str_replace('%2F', '/', $path);
	$path = str_replace('%3A', ':', $path);
	$path = str_replace('%26', '&', $path);
	$path = str_replace('%27', '\'',$path);
	$path = str_replace('%28', '(', $path);
	$path = str_replace('%29', ')', $path);
	$path = str_replace('%5C', '',  $path);		// remove backslash from \'
	$path = str_replace('+', '%20', $path);
	setcookie("localpw", getToken(10), 0, $path, ".$domain", false);
	print_header($accessOK);
	print_fwd($accessOK, $path);
}

function getToken($length=8) {
	//$arr	= array_merge(range('0', '9'), range('a', 'z'), range('A', 'Z'));
	$arr	= array_merge(range('0', '9'), range('a', 'z'), array('#','&','@','$','_','%','?','+','-','!','(',')','=','/'));
	mt_srand((double)microtime()*1000000);		// shuffle array
	for ($i = 1; $i <= (count($arr)*2); $i++) {
		$swap	= mt_rand(0,count($arr)-1);
		$tmp	= $arr[$swap];
		$arr[$swap]= $arr[0];
		$arr[0]= $tmp;
	}
	return substr(implode('',$arr),0,$length);
}


//
// Check GET/POSTed variables
//
function SetVar ($var_name, $mandatory) {
      if (isset($_REQUEST[$var_name]))
            return rawurldecode($_REQUEST[$var_name]);
      else  {
            if($mandatory) PrintError($var_name . " not set.");
            return "";
      }
}



//  -----------------------
//  M a i n   P r o g r a m
//  -----------------------
//

// init
$galleryPath	= "nopath";
$inputPW	= "nopw";
$PWstring	= "nopw";
$foundPath	= "nopath";
$foundPathNum	= 0;
$myDomain	= preg_replace('/^[Ww][Ww][Ww]\./', '', preg_replace('/:[0-9]*$/', '', $_SERVER[HTTP_HOST]));

// check GET/POSTed variables (0/1 = not/mandatory)
$url_params = array(
	"path"		=> 0,
	"gallery"	=> 0,
	"passw"		=> 0,
	"code"		=> 0,
	"show"		=> 0,
	"lid"		=> 0,
	"slide"		=> 0,
);

foreach($url_params as $key => $val) {
   // example:  $path = SetVar("path", "");
   eval("\$" . $key . " = SetVar(\"" . $key . "\", " . $val . ");");
}

// make manually entered foldername an absolute path
if($gallery != "") $path = make_absolutePath($gallery);
if($path  != "") $galleryPath = $path;
if($passw != "") $inputPW     = $passw;

$hidden_fields = "";
if($code  != "") $hidden_fields.= "<input type=\"hidden\" name=\"code\"  value=\"$code\">\n";
if($show  != "") $hidden_fields.= "<input type=\"hidden\" name=\"show\"  value=\"$show\">\n";
if($lid   != "") $hidden_fields.= "<input type=\"hidden\" name=\"lid\"   value=\"$lid\">\n";
if($slide != "") $hidden_fields.= "<input type=\"hidden\" name=\"slide\" value=\"$slide\">\n";

if($inputPW == "nopw" || $inputPW == "") {
	// ask for password
	print_header($pageTitle);
	input_password($enterPW, $hintPW);
}
else {	// check password

    // (1) use gallery folder name as password
    if($dirIsPW == 1) {
		$galleryPath = make_absolutePath($inputPW);
		if (file_exists($inputPW . "/index.htm") || file_exists($inputPW . "/index.html")) {
			fwd2gallery($galleryPath, $myDomain);
		}
		else {
			// gallery not found, wrong folder name
			print_header($pageTitle);
			show_error($wrongPW);
			input_password($enterPW, $hintPW);
		}
    }
    else {
    // (2) use password.php file
	$foldername	= array();
	$passwords	= array();
	include('passwords.php');
	
	// (2A) path was specified
	// ----------------------
	if($galleryPath != "nopath") {
		$relGalleryPath = get_relativePath($galleryPath);
		// search foldernames
		for ($i=0; $i < count($foldername); $i++) {
			if($foldername[$i] == $relGalleryPath) {
				$PWstring = $passwords[$i];
			}
		}
		
		if($PWstring != "nopw") {
			// gallery found, now check password(s)
			$pwOK = checkPW($inputPW, $PWstring, $caseSensitivePW);
			if($pwOK == 1) {
				// access granted!
				fwd2gallery($galleryPath, $myDomain);
			} else {
				// wrong password, try again
				print_header($pageTitle);
				show_error($wrongPW);
				input_password($enterPW, $hintPW);
				if($caseSensitivePW == 1)
					echo "<br><i><span class=\"note\">$noteCase</span></i>";
			}
		}
		else {
			// gallery not found in passwords.php
			print_header($pageTitle);
			show_error($wrongGal);
			input_password($enterPW, $hintPW);
		}
	}
	
	// (2B) no path was specified
	// -------------------------
	else {
		// search passwords
		for ($i=0; $i < count($passwords); $i++){
			$pwOK = checkPW($inputPW, $passwords[$i], $caseSensitivePW);
			if($pwOK == 1) {
				$foundPath = $foldername[$i];
				$foundPathNum++;
			}
		}
			
		if($foundPath != "nopath") {
			if($foundPathNum == 1) {
				// access granted!
				$galleryPath = make_absolutePath($foundPath);
				fwd2gallery($galleryPath, $myDomain);
			}
			else {
				// password appeared in multiple galleries
				print_header($pageTitle);
				input_galleryname($enterGal, $inputPW);
			}	
		}
		else {
			// password not found in passwords.php
			print_header($pageTitle);
			show_error($wrongPW);
			input_password($enterPW, $hintPW);
		}
	}
    }
}

echo "</center></body></html>";
?>

Any idea or suggestion as to what may be happening would be appreciated.
 
Line 251 of that script:
PHP:
$myDomain	= preg_replace('/^[Ww][Ww][Ww]\./', '', preg_replace('/:[0-9]*$/', '', $_SERVER[HTTP_HOST]));

Should be written like this (scroll to the end of the line on both):
PHP:
$myDomain	= preg_replace('/^[Ww][Ww][Ww]\./', '', preg_replace('/:[0-9]*$/', '', $_SERVER['HTTP_HOST']));

Note the quotes.

The script is still working as before, php is being intelligent and converting the variable name into a string.

The warning is telling you is should be a string, hence:
Code:
HTTP_HOST - assumed 'HTTP_HOST'
 
I changed that to a string but it is still throwing the same error message.
 
Nevermind,
I have two domains that use the same script and I changed it on the production side and not the test side (where I was working).

That fixed the problem.....

Thanks for the help.....

I know if I showed up here I would find someone who knew what to do....as I always say "ALWAYS TRUST A MAC USER" LOL

Thanks again.

Douglas
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.