Flipkart

Friday, April 23, 2010

Flex with PHP Usefull Links for Beginners

http://onlamp.com/pub/a/onlamp/2007/07/19/introduction-to-flex-using-php.html

http://livedocs.adobe.com/flex/3/html/help.html

http://cookbooks.adobe.com/post_Dynamic_Images___Buttons_in_Datagrid_using_MYSQL__-8703.html

Flex: Get Response from HTTPService

 <mx:Script>
        <![CDATA[
           import mx.rpc.events.ResultEvent;
           import mx.rpc.events.FaultEvent;
           import mx.controls.Alert;
           private var alert:Alert;



            private function send_data():void {
                userRequest.send();
            }

            private function httpService_fault(evt:FaultEvent):void {
                var title:String = evt.type + " (" + evt.fault.faultCode + ")";
                     Alert.show(title);
            }
          
             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";
                    var request:URLRequest = new URLRequest(url);
                    navigateToURL(request);                
                   //Alert.show('correct');
              }else{
                  Alert.show(msg);
              }
             
            }
   
          
        ]]>
    </mx:Script>

      <mx:HTTPService
            id="userRequest"
            url="http://localhost/flex/firstapp/index.php"
            method="POST"
            fault="httpService_fault(event);"
            result="httpService_result(event)"
            resultFormat="e4x"

            >

Wednesday, April 21, 2010

Drupal: Turn off Register_Globals

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

Tuesday, April 20, 2010

Facebook: Set Username for your pages

Here is the URL http://www.facebook.com/username/ where you can set the username for all your  pages  as well as for your account like:
http://facebook.com/< username >

Add Boxes to the Wall Sidebar of Your Facebook Page

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.

Friday, April 16, 2010

mysql - Reset Root User Privileges

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:

skip-grant-tables

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');

OR
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.

Thursday, April 15, 2010

How to know who are online at present in any system

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'");

Wednesday, April 14, 2010

Write PHP Code in HTML File

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.

Tuesday, April 13, 2010

prototype.js / jQuery.js conflict and resolution

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>
<script src="jquery.js">
</script>
<script>
     jQuery.noConflict();

     // Use jQuery via jQuery(...)
     jQuery(document).ready(function(){
       jQuery("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();
   
</script>






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>
<script src="jquery.js">
</script>
<script>
     var $j = jQuery.noConflict();

     // Use jQuery via $j(...)
     $j(document).ready(function(){
       $j("div").hide();
     });

     // Use Prototype with $(...), etc.
     $('someid').hide();
   
</script>



Thursday, April 8, 2010

PHP : Convert PDF Image file to JPEG Using Image magick

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';
makeThumbnail($file,$out);

? >

Getting Image magick working on XAMPP for Windows

 First you'd download the newest binary release of Image Magick from http://www.imagemagick.org/script/binary-releases.php#windows. The typical version you'd want to snag will end with Q16-windows-dll.exe. For example, the version I downloaded was ImageMagick-6.4.9-4-Q16-windows-dll.exe. Install Image Magick.

After that you need to download php_imagick_dyn-Q16.dll from here.
if you did not find any php_imagick.zip file just refresh once on above URL.

Once you have download   php_imagick_dyn-Q16.dll file put this in xampp/php/ext or php/extension folder.

Then open php.ini and add extension=php_imagick_dyn-Q16.dll.and comment extension=php_imagick.dll if it is already not commented .

And just restart your server.

Tuesday, April 6, 2010

Opening a file download dialog from a JavaScript function

< script type="text/javascipt" >
function startDownload()
{
var url='http://server/folder/file.ext';
window.open(url,'Download');
}
< /script >

hide JavaScript errors from the user

$(window).error(function(){
return true;
});

PHP File Download

// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];

if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);