Archive for the PHP Category

Retrieve time period like facebook fashion

Posted by mahmud ahsan on July 14, 2010 in Facebook, PHP | 1 Comment

facebookIn facebook stream you’ll see the time period at the bottom of the stream. For example: 4 minutes ago, 2 days ago, 3 weeks ago…. In our recent project we have to show similar time fashion for our application’s activity stream. So I write a function to retrieve the time duration.

In our mysql database, we used a column named ‘created‘ as DATETIME in the table. I retrieve that created field as unix_timestamp. So the sql query looks like “SELECT UNIX_TIMESTAMP(created) as created from tableName

After getting the data I just pass the created value in my function. Here is the function:

Continue

Are you defensive programmer?

Posted by mahmud ahsan on June 23, 2010 in PHP, Technology | 10 Comments

defensive programmingSo what is defensive programming? Shortly said, in any problematic situation your code doesn’t break rather bypass the situation by taking proper steps. If you want to know details just visit wikipedia

I am just writing this article because I found that many programmers don’t accept this approach. So if you provide unexpected data sometimes the application will crash or show you unwanted error message and sometimes important data (for web application).

Continue

MySQL random data selection

Posted by mahmud ahsan on April 26, 2010 in MySQL, PHP | 13 Comments

mysqlSome days ago I was working in a vocabulary game and dictionary. The dictionary contains 1,10,000 words and meanings. I developed a vocabulary game where I had to randomly choose 10 words out of 1,10,000 dataset. Here I’m describing the possible solutions for this problem and which solution I used.

Data table

Table name is dictionary and it has id, word and meaning fields. id contains auto incremented id and it is unbroken sequence 1,2,3…..n.

id word meaning
1 aback Having the wind against the forward side of the sails
2 abandon Forsake, leave behind
….. ….

Continue

How to get rank using mysql query

Posted by mahmud ahsan on February 28, 2010 in MySQL, PHP | 15 Comments

mysql Some days ago I was working in a quiz project. Where user will play quiz and for each correct answer they will earn points. One of the task of this quiz application was, to get rank of a particular user. Now I am showing how could I solve this problem using mysql query.

Here is the table structure:

CREATE  TABLE IF NOT EXISTS `quiz_user` (
`uid` BIGINT UNSIGNED NOT NULL ,
`participated` SMALLINT UNSIGNED NULL DEFAULT 0 ,
`correct` SMALLINT UNSIGNED NULL DEFAULT 0 ,
`wrong` SMALLINT UNSIGNED NULL DEFAULT 0 ,
`created` DATETIME NULL ,
`updated` DATETIME NULL ,
PRIMARY KEY (`uid`) )
ENGINE = InnoDB

Continue

How to use amazon s3 using php

Posted by mahmud ahsan on February 12, 2010 in Framework, PHP | 2 Comments

amazons3Amazon Simple Storage Service is designed to make web-scale computing easier for developers. If you have a medium to high traffic web application then S3 will help you to load your content faster. Here contents may be files, photos, videos or even text. Normally S3 is used for files, photos and videos. It gives any developer access to the same highly scalable, reliable, fast, inexpensive data storage infrastructure that Amazon uses to run its own global network of web sites.

3 months ago I developed a project for one of my client using Zend Framework. 1 week ago he told me to change the photo uploading system from hosting disk to amazon s3. Yesterday I implemented s3 for him and found its really very easy using Zend framework.

Here I’m describing how did I do so:

Continue

Develop dynamic flash widget using PHP & ActionScript 3.0

Posted by mahmud ahsan on February 3, 2010 in ActionScript, Facebook, PHP | 3 Comments

flash_php_fb
Basically I’m mainly php base web application developer. But I have  much interest in ActionScript project. Sometimes when I get opportunity I work on it. Someday ago, I was assigned in a project, where I’ve to develop a Flash Widget using ActionScript 3.0 and php. This widget will be use mainly for facebook page.

So shortly the project requirements are:

  1. Develop a dynamic flash widget using ActionScript 3.0
  2. Communication between ActionScript and PHP API
  3. This widget should be working on any facebook page

To develop this project I’ve learned a new library called amfphp. Using this library its much easier and practical to communicate between ActionScript and php. In this article, I’ll show how to use amfphp and develop a dynamic flash widget.

Continue

Obfuscate your email in webpage

Posted by mahmud ahsan on January 1, 2010 in PHP | No Comments

If you have blog or website where you placed your email address, you may notice that there might be many spam emails send to your email address. This is because spammer scour the web to harvest email addresses. So to prevent this problem you can use obfuscated email address. Here I am showing a simple hack to solve this problem.

<?php
     $link = 'mailto:' . 'awoman@gmail.com';
     $coded = "";
     for ($i=0; $i<strlen($link); $i++){
         $coded .= "&#" . ord($link[$i]) . ";";
     }
?>

<a href="<?=$coded?>">Email Awoman</a>

In browser normal user will show simple html link like: Email Awoman but if you see the view source you ‘ll see

<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#97;&#119;&#111;&#109;&#97;&#110;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;">Email Awoman</a>

The code is very simple. Using email address, create a mailto link and then loop though the characters by replacing each character with ASCII equivalent.

Publish facebook page status or wall post automatically

Posted by mahmud ahsan on December 17, 2009 in Facebook, PHP | 13 Comments

fb_logoFacebook page is now very popular. Many companies and people create facebook page for their own publicity. Suppose your company has 100 products and they want to maintain 100 facebook pages, then isn’t it very difficult to update status all of the pages manually?

In this article, I’ll show and discuss about 2 facebook api, using that you can easily update your facebook page status or publish wall post on that page automatically

I assume that you know how to set cron from hosting admin panel, I also assume that you have intermediate knowledge of facebook application development and their api usage.

fb_page

Continue

YouTube Search functionality in facebook app

Posted by mahmud ahsan on December 2, 2009 in FB Connect, Facebook, PHP | 2 Comments

fb_logoSomeday ago I had to add youtube video search functionality in a facebook app. Here I described how I added youtube search functionality in that facebook app using Zend_Gdata php library.

Here is a screenshot of that facebook application, where I added YouTube video search functionality.

search_youtube_video

Continue

Develop auto post publishing twitter app

Posted by mahmud ahsan on November 30, 2009 in PHP, Twitter | 15 Comments

twitterTwitter is a free social networking and micro-blogging service that enables its users to send and read messages known as tweets. Though according to CEO of Twitter he says “We think of Twitter as it’s not a social network, it is an information network. It tells people what they care about as it is happening in the world.”  Though first people personally use twitter for their own purpose, but now twitter is very popular in business world. Many companies are using twitter to promote their business, inform people about their products, services.

In this article, I’ll show how you could develop a basic twitter application using php and twitter api, that will auto publish your predefined tweets. Continue

Page 1 of 41234»