Skip to main content

Posts

Detecting the flash player version

If a user is using a browser with a flash player that is not upgraded, we can show him a message to upgrade his flash player.... using the swfobject javascript. The below code can show the upgrade message over the video, which is run using the jwplayer. <html> <head> <script type='text/javascript' src='jwplayer.js'></script> <script type="text/javascript" src="swfobject.js"></script> </head> <body> <div id="video_player"></div> <script type="text/javascript">     var so = new SWFObject('player.swf','flashContent','280','240','11');     so.useExpressInstall('expressInstall.swf');     so.addParam('allowfullscreen','true');     so.addParam('allowscriptaccess','always');     so.addParam('bgcolor','#FFFFFF');     so.addParam('allowfullscreen','true...

php debugging

The simplest way to debug our php code is to write the data to a log file. For example, this code prints an array to a text file.... <?php $myFile = "logFile.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = '';                foreach($elem as $k=>$v) $stringData .= $k.'=>'.$v."\n";                fwrite($fh, $stringData); fclose($fh); ?> Dont forget to view the file in its stored location...

php array to xml example

This is an example of generating an xml output format from the database. This code is creating a sample rss feed from the joomla articles (which can be added to a rss.xml file). <?php     $dbhost = "localhost";     $dbuser = "root";     $dbpass = "";     $dbname = "joomla";     mysql_connect($dbhost,$dbuser,$dbpass);     mysql_select_db($dbname);     mysql_query("SET NAMES 'utf8'"); // to get proper format         $sql = "SELECT id, title, alias, title_alias, metadesc FROM `jos_content`     where catid=12 limit 3";     $q   = mysql_query($sql) or die(mysql_error());     $xml = "";     while($r = mysql_fetch_array($q)){       $xml .= "<item>";       $xml .= "<title>".trim($r['title'])."</title>";  ...

php validate image type

You can validate image in php, this way: <?php     $img = "banner.gif"; // an image     $info = getimagesize($img);     print image_type_to_mime_type($info[2]); ?> The outout will generally be: image/jpeg or image/gif or image/png But if it is: application/octet-stream, then the file is not an image.

Interview questions

These are some of the php and mysql interview questions i faced: > difference between HAVING and WHERE clause in mysql > how can you interchange the genders of male and female in a mysql table having the column gender with values 'male' and 'female' (refer: http://stackoverflow.com/questions/8400617/mysql-replace-values-in-a-table ) > What is the use of singleton class in php

How to edit php.ini in the cpanel

It is often required to change some settings in the php configuration of our site. If you have access to the cpanel of your hosting provider, then the below steps can help you in modifying the settings in php.ini file..... (Note: these steps are specific to hostmonster) Step 1- Login into your cPanel. Step 2- Under the Software/Services category, click on the PHP Config icon. Step 3- In this screen, there is a section called Install Default php.ini. Under that section, please check mark the "IonCube" and the "SourceGuardian" check boxes (Many commercial php scripts need these turned on - if you think your script may not require the IonCube or SourceGuardian packages, it is okay to not check mark the boxes - but it will not hurt anything to check mark both boxes.). Step 4- Under the same section, click the "INSTALL PHP.INI MASTER FILE" button. Step 5- You have just successfully installed the "php.ini.default" file . But the next step is to r...

Mysql queries (complex)

Scenario-1 : Using the count or sum with inner join query Table structures: videos: id, title, description, date_uploaded categories: id, category_name votes: id, videoid, vote, date (vote will range between 1 and 5) Query: SELECT v.id as vid, v.title, v.description, v.date_uploaded, c.category_name, v2.total, v2.count FROM videos v inner join categories c inner join (select videoid, sum(vote) as total, count(*) as count from votes group by videoid) v2 on v.category_id=c.id and v2.videoid=v.id and v.featured=1 and v.published=1 order by v.date_uploaded desc; Resultset: vid  title  description    date_uploaded            id    category_name   total  count 12   Ford   inauguration 2011-10-07 01:08:22    3    Inauguration        97     31 9     Nano   n...