Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Autoindex for PHP Built in Web Server

Today, while working on the Atropa Toolbox, I wanted an autoindexing option for the PHP built in webserver like the Apache HTTP server has. By default the PHP server was giving me 404 errors whenever I would request a directory that didn't have an index.php file in it. The documentation said that the PHP command line web server would recognize index.html files but that didn't appear to be working for me. There wasn't a chance I was going to create hundreds of index.php files just to be able to navigate through directories on my server, so I wrote a router script to automatically generate a hyperlinked list of files and directories when I reach a folder that doesn't have an index.php or index.html file. The router recognizes index.html and will redirect the browser to it if present. While it isn't as fancy as the autoindexing options on the Apache server, it gets the job done. I can now click on the names of files and folders and make my way through the filesystem on the PHP commandline webserver. If you would like a copy of the router I'll post the code below. Any updates I make to this basic router will be incorporated into the Atropa Toolbox currently hosted on google code.

Closures in PHP

Closures in PHP

Have you ever wanted to generate functions on the fly with PHP like you can in JavaScript? Well, the short answer is that you can and it has everything to do with closures. I'll break it down briefly for you and then take you through an example, step by step, so you can see just how awesome "use" is in a function definition.

Closures Let You Define a Function that Defines a Function Using use

PHP's Built In Server: Super Fun Basic Example

PHP's Built In Server: Super Fun Basic Example


So I'm half asleep at 8 p.m. Surfing the net and typing and
probably dreaming of inebriated ducks gleefully flapping
Poised and paddling in slanted lines across the swamp
Inside my head

Wait...