Document root script acting weird

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Document root script acting weird

Post 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 . "/";
	}
}
?>
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

If you remove the http:// on line 35 then the script won't timeout but it will error out.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

Figured it out. I was missing a ==, had a = instead.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

damn infinite loops. :twisted:
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

You're telling me, geesh!
Post Reply