note 42249 added to function.highlight-file

From: Date: Sun, 09 May 2004 17:56:31 +0000
Subject: note 42249 added to function.highlight-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-69382@lists.php.net to get a copy of this message
To respond to nicispac's post above and to anyone else, if you only want people to view certain pages simply do a little bit of simple coding: <? // Assuming that $page is the page the user requested $whitelist = array ( // Set up an array of allowed pages - the "whitelist" "index.php", "source.php", "usage/index.php", "footer.inc" ); // $checked below just makes sure that a URL that has // already been allowed doesn't get checked again, and // threfore marked as dissallowed $checked = false; reset($whitelist); foreach($whitelist as $allowed){ // For every URL on the whitelist... if($checked != true){ // If it hasn't been allowed yet... if($allowed == $page){ // And if it matches the requested URL... $allow = true; // Allow the URL $checked = true; // And mark that it has been allowed already }else{ $allow = false; // Else, don't allow it and go onto the next URL } } } // Then, all you have to do is a simple IF statement // In this case, I also put in that you make sure the file // exists, it is a .php file, and that it is allowed. // But, only the last part is neccesary in this example if(file_exists($page) AND ereg("(\\.php|\\.inc)$", $page) AND $allow == true){ highlight_file($page); }else{ echo "Sorry, that page either does not exist,"; echo " or it is not a PHP file (.php or .inc),"; echo " or the file is protected from highlighting."; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.highlight-file.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42249 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42249&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42249&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69382) next »