Get the headers sent from the browser with PHP

I recently needed to be able to see what headers the browser sent to the web server with PHP for testing purposes. This is possible using the apache_request_headers() function but it only works if PHP is run on Apache as a module. This post shows usingapache_request_headers() and also an alternative when PHP is run as a CGI. I believe this second method works for lighttpd but have no idea if it works for IIS.

Categories PHP

PHP for loops and counting arrays

It’s well known that calling count($array) in a for loop in PHP is slower than assigning the count to a variable and using that variable in the for loop instead. However until recently, I wasn’t aware that the assignment to a variable can be done in the for loop itself and share this here in this post.

Categories PHP

410 “Gone” with PHP

If a resource has been removed from a website, will not be available again and no forwarding address is available then it should return a 410 "Gone" HTTP status. This post explores the 410 status compared with a 404 "Not Found" and 301"Moved Permanently" and shows how to do a 410 with PHP.

Categories PHP

Get the number of days in a month with PHP

This post shows how to get the number of days in a month with PHP by specifying the year and month. This can be useful when generating a calendar application without having to manually code in the number of days each month has, and not having to worry about the number of days in February which varies on leap years.

Categories PHP