note 42249 deleted from function.highlight-file by tomsommer

From: Date: Sun, 09 May 2004 18:04:41 +0000
Subject: note 42249 deleted from function.highlight-file by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-69383@lists.php.net to get a copy of this message
Note Submitter: admin at linuxbytes dot net ---- 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."; } ?>

« previous php.notes (#69383) next »