Re: Parsing back directories to DOCUMENT_ROOT?

From: Date: Wed, 07 Jun 2000 17:23:05 +0000
Subject: Re: Parsing back directories to DOCUMENT_ROOT?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-1235@lists.php.net to get a copy of this message
Thanks man. Good point (pardon the pun). 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]); elseif ($a_path[$i] == "..") { unset ($a_path[$i]); $j = $i-1; while (!isset ($a_path[$j])) { $j--; } // while unset ($a_path[$j]); } // elseif } return implode ("/", $a_path); } Ryan On Tue, Jun 06, 2000 at 10:21:16PM -0700, The Doctor What wrote: > * 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 ---end quoted text---

« previous php.general (#1235) next »