Archive for April, 2010


>Flex: Get Response from HTTPService

Posted: April 23, 2010 in Flex

> <mx:Script>
           import mx.controls.Alert;
           private var alert:Alert;

            private function send_data():void {

            private function httpService_fault(evt:FaultEvent):void {
                var title:String = evt.type + ” (” + evt.fault.faultCode + “)”;
             private function httpService_result(evt:ResultEvent):void {
              var msg:String = userRequest.lastResult.responce;
              if(msg == ‘1’) {
                    var url:String = “http://localhost/flex/firstapp/home.html&#8221;;
                    var request:URLRequest = new URLRequest(url);



>Drupal: Turn off Register_Globals

Posted: April 21, 2010 in Drupal

>Method 1

Place a file called php.ini in your accounts root directory with the following content: register_globals = false (you can also try using ‘off’, or ‘0’instead of ‘false’).

Method 2

Place a file called .htaccess in your acccounts root directory with the following content:
php_flag register_globals off

>Here is the URL where you can set the username for all your  pages  as well as for your account like:

>Here are the steps to adding a left sidebar ad/button/image to your Facebook Page wall:
1. Click the “Edit Page” link on your Fan Page main page
2. Install the “Static FBML” Application from Facebook.

  • Look for the “More Applications” box at the bottom of the edit area.
  • After you search you should see the “Static FBML” application in the search results.
  • Click on the “Static FBML” link.

3. Add the Static FBML application from Facebook to your Fan Page

  •    Click the “Add to my Page” link on the Static FBML page.
  • After you click the “Add to my Page” link you may get a selection popup that asks which Facebook Page you want to add the application to. Just click the “Add to Page” button for the appropriate page.

4. Add content to the Static FBML application

  •    Now you need to get back to your Facebook Page that you just added the Static FBML application to and click the “Edit Page” link again. 
  • There should be a new box in the middle of the edit page
  • Click the “Edit” link.
  • Now you will see a very simple editing interface with “Box Title:” and “FBML:” fields.
  • The Box Title is just text, but the FBML field can take HTML or FBML.
  • Insert the your code into FBML field:
  • Click “Save Changes” at the bottom. 

5. Move the new FBML box to the Wall page

  •  Go back to your main Facebook Page tab. Then go to the “Boxes” tab. You should see your code 

Thats it.

>mysql – Reset Root User Privileges

Posted: April 16, 2010 in MYSQL

>1. Find the my.ini file (my.cnf for linux). On windows, the my.ini file is typically in your install directory: c:\Program Files\MySQL\MySQL Server 5.1\my.ini
OR if your using xamp then it will be C:\xampp\mysql\bin\my.ini
Open the file with notepad (or any text editor) and add the following entry under the [mysqld] section:


Then, save the file and restart the MySQL service.

If you have Phpmyadmin then select the mysql databese and open the user table. In that you will find the all mysql users.

Then you need to edit the root row and update all the radio buttons with Y.

If you dont have Phpmyadmin then
mysql > use mysql;
Delete the old root user like
mysql > delete from user where user=’root’;

Create root user again (WITH RIGHTS!)

mysql > INSERT INTO user (Host, User, Password, Select_priv, Insert_priv,
Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv,
Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv,
Index_priv, Alter_priv) VALUES (‘localhost’, ‘root’, PASSWORD(‘thepass’),
‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’);

you can update the above instead of re creating the user account.

After that remove the skip-grant-tables from the my.ini file and restart the Mysql. thats it.

>We can find out who are online or logged in to the system. This also displayed as members active now at the footer of any site or in any login system. This is integrated in any login system of any site. We will try to learn how such a system works and display the names ( or user ids ) of the members active at the site. This is part of any system where members login with their user id and password.

As you can understand the member session details after login are stored at server side and not at the client end. So getting the details from the server is not possible as scripts will not have root access. So we will try to maintain one more parallel system to know who are logged in. Here some steps we have taken exclusively for this and let us learn different steps of this script.

Storing the login information in a table
Every time a member successfully loges in we will store the details by adding a record to our table exclusively created for this purpose. We call this table as plus_login. It has five fields storing session id inside field name id, usrid storing user id of the logged in member, ip address of the system from where member has logged in, time of logging in the field name tm and status which will be setting to OFF once the member logged out and we will set it to ON by default. So once a member logged in we will store all these information by inserting a record where the status by default gets set to ON. The structure of the table ( sql dump ) is available inside the download zip file at the end of this tutorial.

Updating the status of the member
We have the status stored in our plus_login table where we have set the status to ON. Along with the status we are also storing the time of logged in. Now we have to update this status to ON and update the new time (field name tm) on every time the member opens inside the member area. We have kept the code to update the plus_table with new time and status to ON inside the page bottom.php. This page bottom.php is called by all pages at the end. This bottom.php page does three jobs. First it update the status of the logged in user with new time and set status to ON. Here is the code of this first step.

$tm=date(“Y-m-d H:i:s”);
$q=mysql_query(“update plus_login set status=’ON’,tm=’$tm’ where id=’$session[id]'”);

Second it mark the status to OFF for all the members who has not interacted with the site within last 10 minutes. ( that is the reason we will be making the status ON and new time for every page call of the member ). Here is the code inside bottom.php for this step.

$gap=10; // Gap value can be changed, this is in minutes.
// let us find out the time before 10 minutes of present time. //
$tm=date (“Y-m-d H:i:s”, mktime (date(“H”),date(“i”)-$gap,date(“s”),date(“m”),date(“d”),date(“Y”)));

Here is the query to do this
$ut=mysql_query(“update plus_login set status=’OFF’ where tm < ‘$tm'”);

At third step it collects the member login ids for which the time is within last 10 minutes and status is set to ON. They are our logged in members or who are active at site. The code you can see one Displaying who are active at site section ( scroll down )

What happens when a user logs out We change the system status to OFF and destroy the session. We have kept this code inside logout page.

$q=mysql_query(“update plus_login set status=’OFF’ where id=’$session[id]'”);

What happens when member does not interact for more than 10 minutes? You can see every time any page is opened and if the page is calling bottom.php page then all users will be changed to status OFF if their tm ( field ) is less than 10 minute of present time. So if no other member has opened any page then the status will not change to OFF. If you think this is to be taken care then you can use one scheduler ( win server ) or cron to run the status update part once in every 10 minutes. Check the query above at the third step.

Displaying who are active at site We have kept the code inside bottom.php file, so from any other page this page can be called. You can see the code inside this page where we have used one simple query to collect the user id for which status is ON and time field ( tm ) is more than present time minus 10 minutes. The query is here .

$qt=mysql_query(“select userid from plus_login where tm > ‘$tm’ and status=’ON'”);

>Write PHP Code in HTML File

Posted: April 14, 2010 in Apache, PHP

>Here is the way to write the PHP logic in HTML File(i.e .html file).

In two ways we can achieve this.

1.change the setting in apache configuration file(i.e httpd.conf)

AddType application/x-httpd-php .php —> AddType application/x-httpd-php .php .html

2. If you don’t have the access to httpd.conf you can write .htacees file as

AddType application/x-httpd-php .php .htm .html

and then restart the apache webserver.


when you use jQuery and prototype javascript frameworks togather on the same page, it creates conflicts.

jQuery has provided a resolution to this conflict. The resolution goes as below:

verriding the $-function:

1) you can override that default by calling jQuery.noConflict() at any point after jQuery and the other library have both loaded. For example:

<script src=”prototype.js”>
<script src=”jquery.js”>

     // Use jQuery via jQuery(…)

     // Use Prototype with $(…), etc.

2) Additionally, there’s another option. If you want to make sure that
jQuery won’t conflict with another library – but you want the benefit
of a short name, you could do something like this:

<script src=”prototype.js”>
<script src=”jquery.js”>
     var $j = jQuery.noConflict();

     // Use jQuery via $j(…)

     // Use Prototype with $(…), etc.

>For this you need to  insatll Ghostscript first, you can download Ghostscript from here.

< ?php

define(‘THUMB_WIDTH’, 150);
define(‘THUMB_HEIGHT’, 212);

function makeThumbnail($in, $out) {
    $width = THUMB_WIDTH;
    $height = THUMB_HEIGHT;
    $identify = shell_exec(“identify -verbose “.$in);
                $matches = array();
                $pattern = ‘/Geometry: ([0-9]{1,})x([0-9]{1,})/’;
        $result = preg_match($pattern, $identify, $matches);
        if( $result && count($matches) ) {
            $h = $matches[1];
            $w =  $matches[2];


    $thumbRatio = $width/$height;
    $inRatio = $w/$h;
    $isLandscape = $inRatio > $thumbRatio;

    $size = ($isLandscape ? ‘1000x’.$height : $width.’x1000′);
    $xoff = ($isLandscape ? floor((($inRatio*$height)-$width)/2) : 0);
    $command = system(“convert $in -resize $size -crop {$width}x{$height}+{$xoff}+0 “.
        “-colorspace RGB -strip -quality 90 $out”);

//     exec($command);
//     echo $command;
$file = ‘scan0001.pdf’;
$out = ‘scan0001_thumb.jpg’;

? >