Page 1 of 1

Document root script acting weird

Posted: Sat May 21, 2005 9:35 pm
by php_wiz_kid
Does anyone know why this is timeing out?

Code: Select all

<?php
function doc_root($root_type) {
	settype($string_position, "string");
	settype($filename, "string");
	settype($doc_folder, "string");
	
	//
	//Retrieve folder path.
	//
	if($root_type == "dir_path" or $root_type == "url") {
		$i = -1;
		while($string_position != "/") {
			$string_position = substr($_SERVER['SCRIPT_NAME'], $i, 1);
			$filename = $string_position . $filename;
			$i--;
		}
		$path_length = strlen($_SERVER['SCRIPT_NAME']) - strlen($filename);
		$doc_folder = substr($_SERVER['SCRIPT_NAME'], 0, $path_length);
	} elseif($root_type == "prev_dir_path" or $root_type == "prev_url") {
		$i = 1;
		$doc_folder = "/";
		while($string_position != "/") {
			$string_position = substr($_SERVER['SCRIPT_NAME'], $i, 1);
			if($string_position != "/") {
				$doc_folder .= $string_position;
			}
			$i++;
		}
	}
	
	//
	//Retrieve and store document path.
	//
	if($root_type == "url" or $root_type = "prev_url") {
		return "http://" . $_SERVER['HTTP_HOST'] . $doc_folder . "/";  //This is what's timing out.  Comment this out and it works.
	} elseif($root_type == "dir_path" or $root_type == "prev_dir_path") {
		return $_SERVER['DOCUMENT_ROOT'] . $doc_folder . "/";
	}
}
?>

Posted: Sat May 21, 2005 9:39 pm
by php_wiz_kid
If you remove the http:// on line 35 then the script won't timeout but it will error out.

Posted: Sat May 21, 2005 10:11 pm
by php_wiz_kid
Figured it out. I was missing a ==, had a = instead.

Posted: Sun May 22, 2005 10:02 am
by phpScott
damn infinite loops. :twisted:

Posted: Sun May 22, 2005 10:14 pm
by php_wiz_kid
You're telling me, geesh!