XEWeb blog, PHP scripts and more...

The working directory in PHP

A colleague recently came to me with this issue that worked fine in their browser, but not on the command line: Warning: include(../config.php): failed to open stream: No such file or directory This warning appeared because of the current working directory. When accessing this script via the browser, Apache found the correct path to the file and so ‘../’ was … Read More

Google Maps – dragging a marker to new position

Something that took me a while to figure out was how to drag a marker on a map to a new position and then retrieve it’s lat/lng (version 3). This assumes you have the map variable set as an instance of google.maps.Map and latlng which is the current position to show on the map as an instance of google.maps.LatLng. var … Read More

Simple PHP caching improved

There are many tools around that will help cache your web pages to increase speed and performance (most notably Memcached) however these usually require installation on your web server, thus rendering them useless for people who use shared hosting and don’t have access to the server. Using some simple PHP code we can quite effectively cache a webpage, useful for … Read More

Flintstone – A key/value database store using flat files for PHP

XEWeb are proud to announce the release of Flintstone, a key/value database store using flat files for PHP. Some of the features include: Memory efficient File locking Caching Gzip compression Easy to use All it requires is PHP 5 and read/write file permissions. Take a look at example usage below: try {       // Load flintstone     … Read More

Generate a random string A-Z, 0-9 in PHP

Often I find that generating a random string can be tedious, there seem to be so many ways to do this. I wrote this simple function to do the work, and it can be easily modified. /*  * Create a random string  * @author XEWeb <http://www.xeweb.net>  * @param $length the length of the string to create  * @return $str the … Read More