note 77106 added to function.array-push

From: Date: Wed, 15 Aug 2007 16:09:34 +0000
Subject: note 77106 added to function.array-push
Groups: php.notes 
Request: Send a blank email to php-notes+get-129499@lists.php.net to get a copy of this message
I had a problem with .htaccess and some tricky encrypted paths (for protecting true dir names of images and files) and created this quick function to auto correct paths for the document root using regex and array_diff <? function fixPath($path){ $temp = trim($path); $temp = eregi_replace("(\./|\.\./)","/",$temp); $temp = eregi_replace("([^/]+(\.htm|\.php))","",$temp); if(!eregi($_SERVER['DOCUMENT_ROOT'],$temp,$regs)){ $partsA = explode("/",substr($temp,0,-1)); $partsB = explode("/",$_SERVER['DOCUMENT_ROOT']); //if the path does not match the dir structure diff the array and reconstruct on the TRUE doc root $tHolder = array_diff($partsA,$partsB); foreach($tHolder as $k=>$v){ array_push($partsB,$v); } $temp = implode("/",$partsB)."/"; } return $temp; } $correctPath = fixPath('.som/phpEncrypted/Path/class/class.QMI.php'); ?> The function strips out filename, checks to see if the path resolves to the doc root, and if it does not it takes the difference in the paths and returns a path that translates to the true path. This is useful for encoding paths where you want to obfuscate the true server path (such as creating external api functions) ---- Server IP: 69.147.83.197 Probable Submitter: 71.43.51.180 ---- Manual Page -- http://www.php.net/manual/en/function.array-push.php Edit -- https://master.php.net/note/edit/77106 Del: integrated -- https://master.php.net/note/delete/77106/integrated Del: useless -- https://master.php.net/note/delete/77106/useless Del: bad code -- https://master.php.net/note/delete/77106/bad+code Del: spam -- https://master.php.net/note/delete/77106/spam Del: non-english -- https://master.php.net/note/delete/77106/non-english Del: in docs -- https://master.php.net/note/delete/77106/in+docs Del: other reasons-- https://master.php.net/note/delete/77106 Reject -- https://master.php.net/note/reject/77106 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129499) next »