Archive for November, 2005

Writing a PHP Page for the googlebot / google’s cache

Here’s something cool to share.

My calcylator project is written in php, it’s one of those “on-line tools” where users can create an account, log in, and can calculate personal profit & loss sheets for ebay.

Like most websites there are “log in” sections, now these pages need to be dealt with differently for search engines & users. Search engines will not be able to log in, but you may still want to deliver some content to them. Take my example, calcylator is running google adsense, and for adsense to work the googlebot (search engine) needs to be able to “see” some content, thinking this through, every time googlebot visited the log in or other protected pages all it would see is “access denied” error pages.

To target google with some “special” content, google kindly present themselves as google in their agent string. Now php even provide a simple tutorial on distinguishing user agent, so this is all I needed to do:

<php

function find_googlebot() {

# This is where we look for the googlebot
$user_agent = $_SERVER["HTTP_USER_AGENT"];

if (preg_match (“/[Gg][Oo][Oo][Gg][Ll][Ee]/”, $user_agent )) {
return true;
}

#For debugging, uncomment this and the agent will appear in the source of the html.
#echo “<!– $user_agent –>”;

}

if (find_googlebot()) {
include(“google-content.php”);
exit;
}

?>

If I quickly run though what I’ve done. We have a function called find_googlebot , we run a test (look for the word google), if we get a match, then we return “true” and run the php google-content.

Here is a working example, if you visit http://www.calcylator.com/index.php?cmd=myhome you’ll see a login page (or your account if you log in) and google will see:

http://www.google.com/search?q=cache:25ez2GhuhDQJ:www.calcylator.com/index.php%3Fcmd%3Dmyhome+site:http://www.calcylator.com

Have fun, just remember, google cache doesn’t update that often, so if you present a mistake, you may be stuck with it for a while ;)

I want a Sony AIBO so much it hurts.

You know the deal, it’s getting close to x-mas time, you start looking at gifts to get for friends & family, not to mention windows shopping for stuff you want.

Yesterday I came across this little guy, a Sony AIBO pet dog. From what I’ve seen on the sony website this dog is da bomb !

There is a long list of cool things this do can do, like interact with it’s environment, learn it’s owners face, speak ! But the features that caught my eye is that it can wi-fi connect to the Internet ! Oh yeah, it can stream you favorite radio station to you, read out RSS feeds and the really funk thing is that it can write it’s own blog !!!! In fact I’ve found on online, and it publishes to WordPress, check out fido’s weblog.

There is a massive catch tho’ , all this coolness doesn’t come cheap, best price I’ve found so far is a huge �1,400 !!! Hummmmm I’m gonna need to think up a get rich quick scheme ! ;)

Sunset Pier on art.gnome.org

Just a quick note to share the joy, My Sunset Pier picture has been accepted into the art.gnome gallery.

Bug Hunting Calcylator

Nearly 10days in, and the bug hunt is in full swing, to be honest life is slowing me down !

I’ve learnt an important lesson it is impossible to fully bug hunt your own app, I know this seems obvious, but the scale of this truth isn’t apparent until someone else starts pulling apart what you have done.

Feedback so far:

  • Many Pages: £ Signs were being formatted incorrectly – fixed
  • Profit Report: Needs simple funds in & out calculation at bottom – added
  • Edit sold page: Error – Cannot update postage type – removed
  • Edit sold page: Massive Bug – fees increment without updating any information – fixed
  • Sell Page: “please type description here” – reported as annoying – removed
  • Help Info: Paypal fees used not shown anywhere – Added paypal helpfile

As a permanent record of feedback received, but not yet implemented please see the project todo list.

New Gallery & New GnomeArt

I’ve been meaning to finish this for a long time now, & I’ve finally finished integrating Gallery2 into my website. The pics section has a direct integration thanks to wpg2.

To celebrate I’ve thrown together a new wallpaper, it’s a sunset at southsea Pier, taken recently. Sunset pictures always make desktops, and this one has some subtle life in it too ;)

Yummy Gnome Sunsetness!

Yummy Gnome Sunsetness!

I’ve released it too on gnome look.

Introducing Calcylator.com !

I’d like to introduce my new website: www.calcylator.com

Calcylator.com is personal project, targeted at ebay sellers. The site is free for people to sign up to, and provide them is a new & different profit & loss (P & L) calcylator, erm sorry, calculator ;)

The wife & I use ebay as an on line car boot sale, one of the things we’ve noticed as sellers is how hard it is to keep track of how much you are spending on listing fees, paypal fees and P & P (postage and packaging) So in my wisdom I decided to write an application to calculate & track that information for me, and now I’m sharing it with the world !!!!

Calcylator is in it’s early stages, I’ve reached the point where we have used it at home for our own use, and now I would like users to embrace it, and help me improve it.

Most P & L calculators out there, are either OS specific download able applications, or subscription services; calcylator.com is w3c standards compliant (so will work in any web browser) and FREE ! Another difference is that most P & L calculators only offer fee calculations, they don’t take into account other expenses such as stock or packaging.

I’ve uploaded some screen shots into my gallery so people can instantly see what I’ve done, but since it’s free you might as well sign up ;)

Over the next few weeks I hope to be implementing some new features, especially any that users contribute. The application defiantly is not stable so if anyone has any problems I’ve set up a calcylator.com contact page ; I’ve also set up a specific RSS feed for calcylator.com for users whom want to know what’s going on, but aren’t interested in my blog.

Please register, play, test and let me know how you get on !

I no longer own Calcylator the domain has moved into different hands :D

Nagios Ping Tool – Another Hack

I’ve received a patch from ed.davison, if you have commented out hosts in your config, you’ll get odd \”address – hostname\” results in the drop down list. Ed’s patch fixes that; thankx :-D

At the moment you’d have to apply the patch your self from the below; but I have a official revision in the pipeline.

-- readhosts.php       2005/11/09 18:07:43     1.1
+++ readhosts.php       2005/11/09 18:08:12
@@ -23,16 +23,20 @@

       $current = trim($line);

-       if (preg_match (\"/addres/\", \"$current\")) {
-               $keywords = preg_split (\"/[\\s,]+/\", \"$current\");
-               $ipaddress[$counter] = $keywords[1];
-               $counter++;
-       }
-
-       if (preg_match (\"/host_name/\", \"$current\")) {
-               $keywords = preg_split (\"/[\\s,]+/\", \"$current\");
-               $node_name[$counter2] = $keywords[1];
-               $counter2++;
+       if (!preg_match (\"/^#/\", \"$current\")) {
+
+               if (preg_match (\"/addres/\", \"$current\")) {
+                       $keywords = preg_split (\"/[\\s,]+/\", \"$current\");
+                       $ipaddress[$counter] = $keywords[1];
+                       $counter++;
+               }
+
+               if (preg_match (\"/host_name/\", \"$current\")) {
+                       $keywords = preg_split (\"/[\\s,]+/\", \"$current\");
+                       $node_name[$counter2] = $keywords[1];
+                       $counter2++;
+               }
+
       }

Xfce 4.2.3.1 – I have a problem

Sorry yum friends, when I saw the announcement from xfce about Xfce 4.2.3.1 I sighed, not because my love for xfce has changed, but I remember what I’d forgotten.

When my place of work moved office I lost my white box build server :-( as soon as I’ve got one, I’ll get the rpms built, in the mean time please see www.xfce.org

Nagios Ping Tool & Nagios QL

Recently I had a request from rex to modify my nagios ping tool (Official Nagios Exchange page); he wanted to use the tool with his nagios configuration.

Rex appeared to be using Nagios QL (Which I believe to be a nagios management tool) , now QL handles nagios config slightly differently . The Ping Tool reads the nagios hosts.cfg file, and turns it into a couple of arrays to use for ping & display, with QL they generate multiple hosts.cfg files, one for each hosts.

Perhaps a short way of saying it, Rex needed to read in multiple hosts.cfg files from a directory, and below is the hack to do it :)

Simply copy & past the below code into a file called readhosts.php, replace your readhosts.php with the new one , and set the variable $hostfilepath in config.php, something like $hostfilepath = “/hosts”; (assuming /hosts is where you keep the files ;-) ) should do the job.

<?php

#This page reads in the hosts described in the config file to an array ready for use later

if ($hostfilepath == "" ) {
        ?>
	<h1> Please update your config file</h1>
	<h2> You need to add the line $hostfilepath = "/path/to/host/config/files"; to config.php </h2>
	<?php
        exit;
}

	#We need a counter to increment for the file array.
	$counter = 0;
	# A second counter is used for the array of actual hosts
	$counter2 = 0;

if (is_dir($hostfilepath)) {

	if ($dh = opendir($hostfilepath)) {

		while (($file = readdir($dh)) !== false) {

			$firstchar = substr($file,0,1);
			if ( $firstchar !== "." ) {
				$full_file_path = "$hostfilepath/$file";

				$lines = file($full_file_path);

				make_host_array();

				#echo "$full_file_path<br>";
			}
		}
       closedir($dh);
   	}
}

function make_host_array() {
	global $lines,$ipaddress,$node_name,$counter,$counter2;

	foreach ($lines as $line_num => $line) {

		$current = trim($line);

		if (preg_match ("/addres/", "$current")) {
	    		$keywords = preg_split ("/[\s,]+/", "$current");
			$ipaddress[$counter] = $keywords[1];
			$counter++;
		} 

		if (preg_match ("/host_name/", "$current")) {
	    		$keywords = preg_split ("/[\s,]+/", "$current");
			$node_name[$counter2] = $keywords[1];
			$counter2++;
		}

	}

#print_r($ipaddress);
#print_r($node_name);

}

?>

Renaming Jak3 Wallpaper

Jak 3 Thumb

I know I’m breaking the code, but I’m renaming the Jak3 wallpaper hosted in my pics section, the reason is that for the 3rd month in a row it is by far the biggest bandwidth eater, & I just can’t afford it :(

Please don’t get me wrong, I love that game, and it makes me happy to see that so many people out there do to, but recently I’ve found a couple if forums out there using the LARGE 2MB file as an AVATAR !!!!!!!!!!!!!!! yes really ! So every time someone reads a post from them, I get stung with a download / bandwidth theft.

If you want use this pic as an avatar please use my pre-shrinked version, or better still download it the image you want an host it yourself.

<img src=”http://www.linickx.com/files/pics/.thumb.jak3-wp-1_1600×1200.png” alt=”Jak 3″ />

Thanks to all, rant over ;-)

Converting HTML to xhtml, a couple of tips.

As part of my blogging re-vamp and a continuation of making sure my site was standards compliant I’ve had to go through the pain of converting my old HTML to new xhtml.

Why did this happen ? Well to be honest I made a bit of a mistake, I’ve had some training on HTML, and have a book too ;-) , so obviously that’s what I started to code my site in, then I introduced wordpress, and unwittingly started to code my theme in HTML, only to find out that all the work I’d done was wrong because wordpress uses xhtml :-(

So what have I learned ? How painful was it ? Well that really depends on your original html, you see my old HTML was mostly in lower case (because I’m lazy) this is contrary to some teaching materials, so if you were really good at using uppercase tags, then migrating to xhtml could be very painful for you.

Basic lessons that got me by were:

  • All code in xhtml MUST be in lower case, this even includes <form action=”POST” > statements, rather it should be <form action=”post” > :-)
  • Short codes cannot be used, i.e. align=center or border=0 isn’t valid anymore, they must be align=”center” and border=”0″
  • Tags must be properly nested, so you can’t do <a><i>something</a></i> it must be <a><i>something</i></a>
  • All tags must be closed, i.e. </p> is now mandatory, and <br> should look like <br /> in fact the same goes for <img> and <input> tags too !
  • Some Tags don’t mix; I’ve found that you can’t open a new <div> without closing a <p> first.
  • And the most important lesson was use http://validator.w3.org/ if you can’t work out what the problem is, googling and changing the tag you’re using worked for me.