Re: Parsing back directories to DOCUMENT_ROOT?

From: Date: Wed, 07 Jun 2000 05:21:16 +0000
Subject: Re: Parsing back directories to DOCUMENT_ROOT?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-1160@lists.php.net to get a copy of this message
* Ryan Adams (radams@fcs.uga.edu) [000605 12:34]: > not elegant, but it might work with your code... > > function fix_path ($p) { > $p = ereg_replace ("//", "/", $p); > > $a_path = explode ("/", $p); > $n = count($a_path); > for ($i=0; $i<$n; $i++) { > if ($a_path[$i] == "..") { > unset ($a_path[$i]); > if (isset ($a_path[$i-1])) > unset ($a_path[$i-1]); > else { > $j = $i-2; > while (!isset ($a_path[$j])) { > $j--; > } // while > unset ($a_path[$j]); > } // else > } // if > } > return implode ("/", $a_path); > > } I really like that. It's really clever. I figured something similar, using recursion. I didn't think to blow away any '..' in the path (and I should do something similar for '.'¸ too). Well, I'll wait for that to happen later, I guess. Does apache correct that? My example is at: http://docwhat.gerf.org/source.php?page_url=/include/mypage.php or for the raw source; http://docwhat.gerf.org/include/mypage.php Search for ShowBackTrace() Ciao! -- When you say 'I wrote a program that crashed Windows', people just stare at you blankly and say 'Hey, I got those with the system, *for free*'. -- Linus Torvalds The Doctor What: Need I say more? http://docwhat.gerf.org/ docwhat@gerf.org KF6VNC

« previous php.general (#1160) next »