Tag Archives: fun

Use PHP to find your mobile browser

I needed a quick way to include different files based on the if the visitor to a site is on a mobile device or a regular browser/computer.

Every browser has a user agent depending on the operating system, browser and system.

below are some common use agents, they can be found by echoing the server variable HTTP_USER_AGENT

< ?php echo $_SERVER['HTTP_USER_AGENT']; ?>

FireFox

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7

Safari Mac

Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-en) AppleWebKit/523.10.3 (KHTML, like Gecko) Version/3.0.4 Safari/523.10 

Safari Windows

Mozilla/5.0 (Windows; U; Windows NT 6.0; en) AppleWebKit/522.13.1 (KHTML, like Gecko) Version/3.0.2 Safari/522.13.1 

Nexus One

Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD56C) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17

Apple iPhone

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

Apple iPod Touch

Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A100a Safari/419.3 

Internet Explorer

Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.2; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)

PHP mobileAgent() Function

Here is my function, is it simple PHP function, is expects one paramerter, and array or expected user agents, but by leaving it blank, the function will use the default user agents.

Update: I have added more mobile user agents for older Android models, Blackberrry’s and the iPhone simulator. .

< ?php
	function mobileAgent($custom_agents = array()) {

		$agents = array_merge($custom_agents, array(
			'iphone',           // Apple iPhone
			'ipod',             // Apple iPod touch
			'aspen',            // iPhone simulator
			'nexus',            // Nexus One Android
			'dream',            // Pre 1.5 Android
			'android',          // 1.5+ Android
			'cupcake',          // 1.5+ Android
			'blackberry9500',   // Storm
			'blackberry9530',   // Storm
			'opera mini',       // Opera mobile
			'webos',            //  Nokia Browser
			'incognito',        // Other iPhone browser
			'webmate'           // Other iPhone browser
		));
		$user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
		foreach($agents as $agent) if(strpos($user_agent, $agent)) return TRUE;
		return FALSE;

	}
?>

Usage

	< ?php if(mobileAgent()): ?>
	
	
	< ?php else: ?>
	
	< ?php endif; ?>

Facebook Pirate Style

With the Millions of users on Facebook, there is a need for lots of different langauges, but did you know that you can view your facebook in Pirate English! It will change the whole site in to Pirate English, even the notification emails you receive.

Facebook in Pirate English

Facebook in Pirate English

It is Easy to turn on, and easy to turn off once the novelty has worn out.

Enable Pirate English on your Facebook Profile

Log in to your Facebook account, Click the Settings Link in the top Right, Click the Langauge tab, and from the drop down select English (Pirate) Button.

Add me to your Facebook !

Torrent Downloading Laws in New Zealand ~ Update

If you download anything via torrents, you should read this article. It is a pretty clear explanation of the upcoming Torrent Laws for ISP’s and users here in New Zealand including the ’3 Strike’ policy.

http://torrentfreak.com/code-aims-to-quell-new-zealand-3-strikes-fears-090204/

The thing about torrents is that not every one uses them to download Copyright Application, music or movies.

I use Torrents and A Torrent Application called Vuze to download FREE content such as video tutorials, TV Adverts, HomeMade or Festival Movie Releases, Music Video Clips and all sorts of content that people have released openly.

I have even worked with a multiple office/location firm that shared its files via a Secure P2P network, this worked well as it pulls files from all locations, increasing speeds and reducing bandwidth usage.

It will be interesting to see what happens over the next 18 months…

Javascript Password generation and strength testing.

While working on an online school application I came across the need to users to be able to change their passwords, I wrote a quick and dirty random pass script, then decided to see if I could figure out how hard it would be to test the strength of the entered password.

Ryan Stemkoski found Phiras’s blog post about a jQuery strength tester. Which I used and modified to reduce all need for any external libraries. (jQuery or Mootools, etc…)

I have a Demo @ http://dev.lendrum.co.nz/passwords/

and you can download the code here.
[download#5]

Mountain Bike Event 1

So, you who know me, know I am pretty darn lazy. So in Saturday I got a call from my sister at 7:30am wanting me to go riding with her, as her friend was sick. I was like “Hell No !”, but she managed some how to talk me in to it.

We headed over to Woodhill Bike Park on to a bike, and 5 minutes later my thighs were burning, 10 minutes they were killing, and 15 minutes later every seconds breath contained a concoction of swear words.

It was hard work, but fun, I didn’t go over any serious or even semi-serious jumps. It was the first time I have been on a bike in years, and may even go again this weekend. I popped a couple of wheelies, and didn’t even fall off!

Clean Dynamic Directory Listing with PHP

This here is a quick couple of functions to dynamically display files from any given directory.

It allows you to display it is a nice format with/out the files extension.

Pretty simple, but comments/suggestions/ bugs are very much welcome!!

< ?php

	// DIRECTORY DISPLAY USING GLOB AND A CLEAN PATH OUTPUT.
	// IF ALL PERIMATORS ARE EMPTY WILL SCNA DEFAULT DIRECTORY
	// '$path'  =>  PATH TO DIRECOTRY TO SCAN
	// '$ext'   =>  FILES EXT,  IF YOU WANT OT ECLUDE IT,  OR ONLY SCAN FOR ONE TYPE OF FILE
	// '$start' =>  APPEND TO START OF OUTPUT LINE EG: '
  • ' OR '
    ' // '$end' => APPEND TO END OF OUTPUT LINE EG: '
    \n' OR '
  • \n' => DEFAULT '\n' function direcotryList($path = "./", $ext = NULL, $start = NULL, $end = "\n"){ $output = ""; $ignore = array(".","..","thumbs.db"); foreach(glob($path ."*". $ext) as $file){ if(is_file($file) and !in_array($file, $ignore)){ $output .= $start . buildLink($file, $path, $ext) . $end; } } } // THIS FUNCTION WILL OUTPUT A CLEAN LINK. // BUILT FROM THE PREVIOUS FUNCTION. function buildLink($file, $path, $ext = NULL){ $len1 = strlen($path); $len2 = strlen($file); $start = ($len1 - $len2); $ext = ($start + strlen($ext)); $file = substr($link, $start, -$ext); $name = str_replace(array("_","-"), array(" "," "), $file); $link = "". ucwords($name) .""; return $link; } // EXAMPLES OF USE // OUTPUT SIMPLE LINKS OF ALL FILES IN THE CURRENT DIRECTORY. echo(direcotryList()); // OUTPUT ALL JPG IMAGES IN DIVS $output = "
    \n"; $output .= direcotryList("images/",".jpg","
    ","
    ","\n"); $output .= "
    \n\n"; echo($output); ?>

    Building a Completely Dynamic site using text files, PHP and no mySQL.

    I spent a fair amount of time trying to help people on PHP forums such as webdeveloper.com : Sheldon and one thing I see on a regular basis is over complex systems for basic site structures with people who at this stage don’t have enough knowledge of PHP to build a secure structure.

    Now don’t get me wrong, their not stupid, and I’m for sure not the greatest !

    So, tonight, a sunday evening, nothing on the tele, and less of a social life lately it seams. I have spent 2 hours building a completely dynamic flat file web structure.

    I built this for a couple of reasons, I have never built a system using a complete class that I have written from line 1. I have worked with classes, and extended classes, but never started from scratch. It was something to do, and.. It could be helpful to others, and that how I roll, I like to help out.

    • Flat file pages
    • Small footprint < 12k
    • No mySQL/ database needed
    • Simple integration
    • Customisable template design
    • Runs on Apache and IIS Severs
    • Supports Apache Mod ReWrite URLs
    • Secure againsts including ‘Bad Files’

    Installation:

    1:Drop it in the directory you wish to run the system.

    2:Customise the ‘index.php’ file with your own HTML, making sure you keep the PHP.

    3:Open ./includes/simpleSite.inc’, find the function ‘config()’ and check that all of the ‘$config[]‘ array values are correct. They should be 99% dynamic.

    This uses a class to construct the functions, so required a late version of PHP 4, but PHP 5 is better If your current web host doesnt offer up to date software contact me via my web design & hosting business Inbox Design

    This is offered as is, I am happy to help out with installing and custimizing the design, If you have any bugs or feature requests, just ask :)

    Free Download: [download#2] -> simpleSitev0.2.zip (Update v0.2)

    Free Download: [download#1] -> simpleSitev0.1.zip

    Moving On

    I live now in greater Auckland. Kauakapakapa. its about 1 hour/ 1 1/2 hours north from the CDB ( Central Business District) I grew up in Kaukapakapa, Went to school in Helensville, Moved to Auckland City for 2~3 years, Moved back to kauakapakapa, Got married, brought a house in Helensville, marriage broke up, whore ran off, moved back to kaukapakapa. Spent 8 months in the USA, came back to Kaukapakapa.

    Did you catch all that ? Thats a lot of moving backwards and forwards to kapkauakapa!

    My Plan.

    6 years ago: Become a Qualified Carpenter, create websites as a side task. ~ Start first home business.

    4 years ago: Qualified Carpenter, Stop building, work full time creating websites. ~ Started Inbox Design

    12 months ago: Recover from personal catastrophe, Move to US to take full time Developer placement. ~ Zipline Interactive

    5 months ago (March 2008) Back to Kaukapakapa, No more Visa’s left. Continuing to work for the US firm, catching up with New Zealand customers

    This week:

    Today, I am ready for something new!

    Today, I am ready for something new! Some where Different!

    Today, I am ready for something new! Some where Different! Somewhere where…

    Wellington

    Today with the help of my bother I am now Actively seeking work in Wellington, New Zealand, The Capital!. How ever, really, I am actively seeking work everywhere. I am now the person with nothing to hold me back, and would be looking to work any where, for that experience, the experience, the experience! It is all about the experience.

    Do you know what is more important than the experience ? It is the people you meet on the way!

    It is those people…