Wednesday, August 31, 2011

Dynamic meta Description, meta Keywords and Title using PHP

Changing your the meta description, meta keywords and title of a php page.This is a follow up of a post that I had posted here a few weeks back.

I only make some changes to the header.php file and the header.php file will handle the value of $section and change the title, the meta description and meta keywords of the webpage.
	//Conditional Statement to change the title, meta description and meta keywords.
	if ($section == "home"){
		$title = "Unique title for home page";
		$description = "A Unique description for 'Home' Section";
		$keyword = "Home";
	}else if ($section == "profile"){
		$title = "Special title for profile page";
		$description = "A Special description for 'Profile' Section";
		$keyword = "Profile";
	}else if ($section == "product"){
		//Another Conditional Statement to change the title, meta description and meta keywords base on the productID.
		$productID = $_REQUEST["productID"];
		if($productID == "x"){
			$title = "Product page for X";
			$description = "A description for 'Product X'";
			$keyword = "Product X";
		}else if($productID == "y"){
			$title = "Product page for Y";
			$description = "A description for 'Product Y'";
			$keyword = "Product Y";
		}else if($productID == "z"){
			$title = "Product page for Z";
			$description = "A description for 'Product Z'";
			$keyword = "Product Z";
			$title = "A title for product page";
			$description = "A description for 'Product' Section";
			$keyword = "Product X, Product Y, Product Z";
	}else if ($section == "contact"){
		$title = "Contact me now";
		$description = "Form for contact me";
		$keyword = "Conact me, form";
	//Write the title, meta description and meta keywords into a header html tag
	echo "<header>";
	echo "<title>".$title."</title>";
	echo "<meta name='description' content='".$description."'>";
	echo "<meta name='keywords' content='".$keyword."' />"; 
	echo "</header>";
	//Create a table and base on the value os $section, toggle the state of the selected button.
	echo "<table cellpadding='0' cellspacing='0' border='0' width='100%' ><tr>";
	//If $section == home, make the text 'Home' unclickable else makt it into a clickable hyperlink
	if ($section != "home"){
		echo "<td align='center'><a href='home.php'>Home</a></td>";
		echo "<td align='center'><b>Home</b></td>";
	//If $section == profile, make the text 'Profile' unclickable else makt it into a clickable hyperlink
	if ($section != "profile"){
		echo "<td align='center'><a href='profile.php'>Profile</a></td>";
		echo "<td align='center'><b>Profile</b></td>";
	//If $section == product, make the text 'Product' unclickable else makt it into a clickable hyperlink
	if ($section != "product"){
		echo "<td align='center'><a href='product.php'>Product</a></td>";
		echo "<td align='center'><b>Product</b></td>";
	//If $section == contact, make the text 'Contact Us' unclickable else makt it into a clickable hyperlink
	if ($section != "contact"){
		echo "<td align='center'><a href='contact.php'>Contact Us</a></td>";
		echo "<td align='center'><b>Contact Us</b></td>";
	echo "</tr></table>";
	echo "<br>";

Click here for the example that I had created for the post.
Try click and copying the following URL1 and URL2 into Facebook and you will see how useful php can be.
Click here for the source codes of the example that I had created.

Friday, August 26, 2011

COMEX 2011

It's time to get ready for COMEX 2011. Time to catch a glimpse of the latest gadgets and at the same time get all the gadget at a promotional price. :P

Image taken form the COMEX website.

Details of COMEX 2011:
  • Venue: Level 1,2,3,4 and 6, Suntec City Convention Hall, Singapore
  • Date: 1st - 4th September 2011
  • Opening hours: 12noon - 9pm

* Click here for the website of COMEX 2011.

Wednesday, August 24, 2011

Flex: Measuring width of text of a Label

I have encounter a few situations in Flex where you need to position 2 labels side by side and the one on the left always ended up to be a dynamic label. If this is Flash, you can always use a .textWidth / .textHeight to solve the problem but in Flex, some of these properties were not available hence here's a workaround for it.


Click here to view the demo.
Click here to download the source file of the demo.

Monday, August 22, 2011

Google Plus - Games Notification

Google Plus+ just added a new section for 'Games' recently. And as compared to the way how Facebook had organised the way game notifications were displayed, I love the way Google is displaying all the game notifications.

This is how Google Plus+ is doing it and I like it. Rather then messing up the feeds of my friends, they have created a seperate section for all these annoying 'Games Notifications'. This my friend is a +1 indeed. Though I still want a -1 button from Google Plus+. Can anyone help me to pass the message to Google asking them for a -1 button?

* Click here to access Google Plus+ website.
^ Click here to access Facebook.

Sunday, August 14, 2011

Flash / Flex AS3: Finding the difference between 2 dates

I have encounter numerous situation where there is a need to compare 2 different dates. I have created a simple example to demonstrate how to find out the difference between 2 dates.

		Days: " + tempArray[0] + "";
				outputTxt.htmlText += "
Hours: " + tempArray[1] + ""; outputTxt.htmlText += "
Minutes: " + tempArray[2] + ""; outputTxt.htmlText += "
Seconds: " + tempArray[3] + ""; outputTxt.htmlText += "
MilliSeconds: " + tempArray[4] + ""; } ]]>

	import mx.controls.DateField;
	import mx.controls.TextArea;

	public class TimeDifferenceMain
		public function TimeDifferenceMain()
		public function compareDate(tempDate:Date):Array
			//2 dates object: 1 is today's date, the other 1
			//is the selected date
			var now:Date = new Date();
			var selectedDate:Date = tempDate;
			//to store the difference of both dates in numerical value
			var remainder:Number;	
			//Store the number of milliseconds of both date since 1970
			var nowNum:Number = now.getTime();
			var selectedDateNum:Number = selectedDate.getTime();
			//Numbers to store number of milliseconds in eash day, 
			//each hour, each minute and each second
			var dayValue:Number = 24 * 60 * 60 * 1000;
			var hrValue:Number = 60 * 60 * 1000;
			var minValue:Number = 60 * 1000;
			var secValue:Number = 1000;
			//Compare which date is bigger and find the difference
			if(nowNum > selectedDateNum)
				remainder = nowNum - selectedDateNum;	
				remainder = selectedDateNum - nowNum;
			//Modulas play a big role here as it is used to find
			//out the remainder of the next smaller unit
			var hrLeft:int = remainder % dayValue;
			dayValue = (remainder - hrLeft)/dayValue;
			var minLeft:int = hrLeft % hrValue;
			hrValue = (hrLeft - minLeft)/hrValue;
			var secLeft:int = minLeft % minValue;
			minValue = (minLeft - secLeft)/minValue;
			var milliSecLeft:int = secLeft % secValue;
			secValue = (secLeft - milliSecLeft)/secValue;
			//Create a array and store the output into the array
			var resultArray:Array = new Array();
			return resultArray;

Click here to view the demo.
Click here to download the source file of the demo.

Sunday, August 7, 2011

Facebook: Changing the description of your websites / blogs

This happen to me quite often in the past. I was building a website or after I had written a new post on one of my blogs, I would immediately copy and paste the URL of the website onto my Facebook wall. Upon doing that, Facebook will show you the title, the description and a series of thumbnail for you to select of the URL that you have pasted. You realise that some parts of the copy were missing due to some illegal characters or you suddenly decided to change the thumbnail of the website. After making that minor change, Facebook will still reflect the same contents as per what you had before you make the minor change. What to do? How to work around this issue?

As long as the same URL have not been shared by any other users, you will still have a way to ask Facebook to update to the latest content.

Click here to move to one of the developer tools that Facebook had created.

Copy and paste the URL that you want to share into the text field and click on the 'Lint' button located next to the text field.

Now, the updated content should be appearing on this webpage and you can start sharing your URL with the correct set of contents now. :)

  • This method will not work after someone had already started sharing the same URL that you are sharing.
  • If this method doesn't work, create a separate server script scripting file and do a redirect from that file. And share the new URL. :D