Thursday, January 31, 2013

how to post your comment into facebook on my web site

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); = id;
  js.src = "//";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-comments" data-width="470" data-num-posts="2" data-colorscheme="light"></div>

facebook wal post api access post and submit post to facebook

Graph API & IFrame Base Facebook Application Development

FacebookFacebook is one of the top social networking site and its easy to develop facebook application. You can also easily integrate facebook features via facebook connect into your site. But it may happen that you want to develop facebook application that will run within facebook site. If this is the case, then this is the right article for you to start.
In this article I discussed all the basics and techniques you need to develop iframe base facebook application.
You’ll learn from this article:
  1. Setup IFrame Application
  2. Facebook Authentication for Iframe Application
  3. Setting extended permission for more information
  4. How to set links
  5. Form Submission technique and getting Data
  6. JQuery – how to use javascript and javascript library
  7. Graph api using php
  8. Stream Publish (wall post)
  9. Status Update via php api
  10. Status Update via javascript api
  11. Invitation Feature
  12. Iframe Resizing
Before proceeding checkout the demo & Download Code
Demo: (this application now runs PHP SDK 3.0 base code)
Download Old Code PHP SDK 2.2
PHP SDK 3.0 Base Updated Code

UPDATED Tutorial and Code

If you’re first time developer then read the full post and then the updated post , otherwise skip this post and just go to the updated post.

Recommended Reading

1. Setup IFrame Application

First visit and setup your facebook application. Set your project server path in Canvas Callback Url, set a canvas page url name, set render method to IFrame, set iframe size Resizable.
facebook app setup screen 1
Set Connect URL to your project server url also
facebook app setup screen 2
Now click save changes . So you just created a new facebook app.
Now download my code and upload all the files to your server’s project dir.
facebook.php is the php-sdk library. Now update configuration of fbmain.php. Copy paste your application’s appid, api key, secret key in $fbconfig. And also set $fbconfig baseUrl and appBaseUrl .
//facebook application
    $fbconfig['appid' ] = "";
    $fbconfig['api'   ] = "";
    $fbconfig['secret'] = "";

    $fbconfig['baseUrl']    =   ""; //
    $fbconfig['appBaseUrl'] =   ""; //
In the template.php you’ll see I load facebook javascript library. Its mandatory to render xfbml tags in your application and also some facebook tasks via javascript.
<div id="fb-root"></div>
    <script type="text/javascript" src="">
     <script type="text/javascript">
         appId  : '<?=$fbconfig['appid']?>',
         status : true, // check login status
         cookie : true, // enable cookies to allow the server to access the session
         xfbml  : true  // parse XFBML
So the application setup is complete.

2. Facebook Authentication for Iframe Application

fbmain.php file is used for facebook authentication also. Here look at this part
//Facebook Authentication part
    $session = $facebook->getSession();
    $loginUrl = $facebook->getLoginUrl(
            'canvas'    => 1,
            'fbconnect' => 0,
            'req_perms' => 'email,publish_stream,status_update,user_birthday,

    $fbme = null;

    if (!$session) {
        echo "<script type='text/javascript'>top.location.href = '$loginUrl';
    else {
        try {
            $uid      =   $facebook->getUser();
            $fbme     =   $facebook->api('/me');

        } catch (FacebookApiException $e) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';
Look we pass an array of configuration in getLoginUrl().  canvas=1 as our app is iframe app.
If we don’t find a valid session or session key is expired, we redirect user to the facebook login page generated by getLoginUrl() function via javascript code top.location.href.

3. Setting extended permission for more information

You couldn’t get some information until user approve your application via extended permission. So look in our above code we provided these extended permissions
‘req_perms’ => ‘email,publish_stream,status_update,user_birthday, user_location,user_work_history’
Checkout extended permission list from here.

4. How to set links

In my application you’ll see menu links like Home, Invite . If you see the code for template.php you’ll see below codes at the bottom.
<a href="<?=$fbconfig['appBaseUrl']?>" target="_top">Home</a> |
    <a href="<?=$fbconfig['appBaseUrl']?>/index.php?page=invite.php" target="_top">
The important thing is that you must provide target=”_top” in all links for your iframe app. Otherwise when you’ll click the link the full facebook will load in the iframe.

5. Form Submission technique and getting Data

One of the most important thing is form submission. If your application have any form then you have to provide action url as your application’s callbackurl. Don’t use facebook application url otherwise you’ll not get form data. And also again use target=”_top” within form tag.
<form name="fs" action=""
 target="_top" method="POST">
Your Name: <input name="name" value="" />
<input name="submit" type="submit" value="Submit" />
And after getting data redirect user to the app url.
if (isset($_REQUEST['submit'])){
    //retrieve form data here
    $name = $_REQUEST['name'];
    //save data to database or do other tasks

//now redirect user
header ("Location:");

6. JQuery – how to use javascript and javascript library

When we develop fbml canvas base facebook application, we only can use partial and modified javascript named FBJS. But in iframe application development you could easily use normal javascript and any javascript library like jquery.
Look the menu in my application. To create this menu here I coded.
In template.php I first load the jquery javascript library and ui library.
<link href="" rel="stylesheet" type="text/css"/>
<script type="text/javascript" 
<script type="text/javascript" 
Then I call the jquery function after the page fully loaded. And it will find the div named ‘tabs’ and make them a nice tabbed menu.
<script type="text/javascript">
            $(document).ready(function () {
And in home.php view file I coded for tab.
<div id="tabs">
        <li><a href="#fragment-1"><span>User Information</span></a></li>
        <li><a href="#fragment-2"><span>FQL Query</span></a></li>
    <div id="fragment-1">
        <img src="<?=$uid?>/picture" alt="user photo" />
        <br />
        <div style="height: 400px; overflow: auto">
            <?php d($fbme); ?>
    <div id="fragment-2">
        <div style="height: 400px; overflow: auto">
            echo "FQL QUERY: " . $fql;
You can also easily use jquery ajax function to do ajax tasks. So its really amazing to use javascript library in your facebook application.

7. Graph api using php

Calling graph api using php sdk its very easy. In my previous article check how to call graph api using php. In fbmain.php you’ll see I called graph api.
$fbme     =   $facebook->api('/me');

8. Stream Publish (wall post)

Its very easy to publish stream via facebook javascript sdk. You’ll see in template.php I loaded facebook javascript library. And you’ll see below code there
    function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
            method: 'stream.publish',
            message: '',
            attachment: {
                name: name,
                caption: '',
                description: (description),
                href: hrefLink
            action_links: [
                { text: hrefTitle, href: hrefLink }
            user_prompt_message: userPrompt
        function(response) {

    function publishStream(){
        streamPublish("Stream Publish", ' is AWESOME. I just learned 
how to develop
 Iframe+Jquery+Ajax base facebook application development. ', 
'Checkout the Tutorial', '',
 "Demo Facebook Application Tutorial");
In home.php view file you’ll see I just call the publishStream() method to show the stream box.
<div id="fragment-3">
        <a href="#" onclick="publishStream(); return false;">Click Here To Show
 A DEMO Stream Publish Box</a>
Visit facebook official library documentation to know more about stream publish.

9. Status Update via JQuery Ajax and php api

In the template.php you’ll see I created a javascript function. This function used jquery ajax functionality to send request to server and load.
    function updateStatus(){
        var status  =   document.getElementById('status').value;

            type: "POST",
            url: "<?=$fbconfig['baseUrl']?>/ajax.php",
            data: "status=" + status,
            success: function(msg){
            error: function(msg){
In the home.php you’ll see I’ve a textarea where user will write something and if click the button it will call updateStatus() javascript function to pass value to server.
<div id="fragment-4">
        <form name="statusUpdate" action="" method="">
            <textarea name="status" id="status" rows="4" cols="50"></textarea>
            <input type="button" onclick="updateStatus(); return false;" 
value="Write Something And Click Me" />
And in ajax.php you’ll see. Here user’s status will update via facebook api.
    include_once "fbmain.php";

    if ($fbme){
        //update user's status using graph api
        if (isset($_REQUEST['status'])) {
            try {
                $status       = htmlentities($_REQUEST['status'], ENT_QUOTES);
                $statusUpdate = $facebook->api('/me/feed', 'post', 
array('message'=> $status, 'cb' => ''));
            } catch (FacebookApiException $e) {
            echo "Status Update Successfull. ";

10. Status Update via javascript api

In template.php you’ll see a javascript function. Where I used facebook javascript api to update status.
    function updateStatusViaJavascriptAPICalling(){
        var status  =   document.getElementById('status').value;
        FB.api('/me/feed', 'post', { message: status }, function(response) {
            if (!response || response.error) {
                alert('Error occured');
            } else {
                alert('Status updated Successfully');
In home.php you’ll see I call this updateStatusViaJavascriptAPICalling() method to update status.
    <input type="button" onclick="updateStatusViaJavascriptAPICalling(); 
return false;
" value="Update Status via Facebook Javascript Library" />

11. Invitation Feature

Checkout the invite.php code
     include_once "fbmain.php";
    if (isset($_REQUEST['ids'])){
        echo "Invitation Successfully Sent";
        echo '<pre>';
        echo '</pre>';
        echo "<b>If you need to save these user ids then save these to database
 <br />then redirect user
 to the url</b>";
        $string = "<script type='text/javascript'>
top.location.href='{$fbconfig['appBaseUrl']}'; </script>";
        echo "Use the following javascript code to redirect user <br />";
        echo htmlentities($string, ENT_QUOTES);
    else {
<fb:serverFbml style="width: 500px;">
    <script type="text/fbml">
                    type="Demo Application |"
                    content="Checkout this demo application and learn iframe 
base facebook application 
development. <fb:req-choice url='<?=$fbconfig['appBaseUrl']?>' label='Accept' />"

                    actiontext="Checkout this demo application and learn iframe
 base facebook application d
<?php } ?>
Read the comments within code. remember if you want the users ids whom a user sent invitation then don’t forget to use callback url not facebook app url. And after getting invited user ids redirect user to the facebook app url.

12. Iframe Resizing

Sometimes you may need to resize your iframe app in runtime. Then use the following code to set iframe size
<script type="text/javascript">
    var obj =   new Object;
I hope this article has given you a clear view to developing iframe base facebook application. Don’t forget to checkout the demo application and to see the codes.
Facebook Official Documentation


       <iframe src="
        scrolling="no" frameborder="0"
        style="border:none; width:450px; height:80px"></iframe>


<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); = id;
  js.src = "//";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like-box" data-href="" data-width="292" data-show-faces="false" data-colorscheme="light" data-stream="false" data-header="false"></div>

Wednesday, January 30, 2013

wordpress malware removal plugin

First download and install your admin area this plugin
  • Automatic removal of "Known Threats".
  • Download definitions of new threat as they are discovered.
  • Automatically upgrade vulnerable versions of timthumb to patch security holes.
  • Customize Scan Setting.
  • Run a Quick Scan from the admin menu or a Complete Scan from the Settings Page.
Updated Jan-5th
Register this plugin at GOTMLS.NET and get access to new definitions of "Known Threats" and added features like Automatic Removal, plus patches for specific security vulnerabilities like old versions of timthumb. Updated definition files can be downloaded automatically within the admin once your Key is registered. Otherwise, this plugin just scans for "Potential Threats" and leaves it up to you to identify and remove the malicious ones.
NOTICE: This plugin make use of a "phone home" feature to check for updates. This is not unlike what WordPress already does with all your plugins. It is an essential part of any worthwhile security plugin and it is here to let you know when there are new plugin and definition update available. If you're allergic to "phone home" scripts then don't use this plugin (or WordPress at all for that matter).

Tuesday, January 29, 2013

Tuesday, January 22, 2013

mysql query pivot table example

Pivot tables are used to simplify extensive data in order to make it easier to read and understand. To pivot table, an aggregate is used against a set of data to distribute multiple rows of a single column into a single row with multiple columns.
CREATE TABLE properties (
  id INT(11) NOT NULL,
  item_id INT(11) DEFAULT NULL,
  (1, 1, 'color', 'blue'),
  (2, 1, 'size', 'large'),
  (3, 2, 'color', 'orange'),
  (4, 3, 'size', 'small'),
  (5, 4, 'color', 'violet'),
  (6, 5, 'color', 'green');
Pivot table output:
  MAX(IF(prop = 'color', value, NULL)) AS color,
  MAX(IF(prop = 'size', value, NULL)) AS size
| item_id | color  | size  |
|       1 | blue   | large |
|       2 | orange | NULL  |
|       3 | NULL   | small |
|       4 | violet | NULL  |
|       5 | green  | NULL  |

Monday, January 21, 2013

all jquery string function list and full demo example

What Is jQuery?

In a nutshell, jQuery is a leading JavaScript library that can perform wonders on your Web pages and make your Web development life much easier and more enjoyable. With the rise in popularity of jQuery since its arrival in 2006, over an estimated 24 million websites (50% of them being the 10,000 most visited websites) currently reap the benefits, and as Google Trends suggests, it’s the most popular JavaScript library.
Thousands of Web developers worldwide use jQuery to innovate on their websites and stay up to date on trends. This surge has been influenced by several jQuery gurus who have helped make jQuery what is today. I would like to personally thank these guys and gals for their hard work and would like to do my part to spread the news about JavaScript and jQuery. In this article, we’ll show you over 50 of jQuery’s most renowned functions, demonstrated with live visual examples. The jQuery library is comprehensive, so hopefully seeing these most frequently used functions in action will improve your understanding of how they can work together to produce excellent results.
(Smashing’s note: If you enjoy reading our articles, you'll love the Smashing eBook Library. Get immediate access to all Smashing eBooks with 70% discount and vote on the topics you’d like to learn more about. We’ll prepare eBooks that fit your needs best! Subscribe now!)

jQuery And CSS

Styles play a big part in the look and feel of any website, and jQuery can help us change them dynamically. In this section, we will look at how jQuery can be used to dynamically add and remove style classes and entire cascading style sheets.


You can change your website’s styles dynamically with jQuery’s .css() function. Either change styles that are already declared inline or in CSS files (such as font-size, color, background-color, etc.) or create new styles for elements.
Demo: Change text color and background color
Run Demo View Code
Demo: Add a style sheet
Run Demo View Code

.addClass() and .toggleClass()

In addition to the .css() function, you can apply currently defined CSS classes by using the .addClass() function. Its counterpart function, .removeClass(), reverses the action.
Demo: Add a CSS class to an element
Click “Run demo” to add the styles to the button. Click “Reset” to remove the styles.
Run Demo View Code
The .toggleClass() function is a huge time-saver for toggling a state on and off with CSS. The following example sets event handlers for mouseenter (which applies the CSS class img-hover to the image) and mouseleave (which removes it).
Demo: Toggle a CSS class on an element
Run Demo View Code

jQuery Animations And Effects

We can use jQuery to create some very smooth animations and effects with minimal effort. Animations and effects are always best demonstrated with examples, so let’s dive right in.


The .animate() function can be used to animate the movement and/or appearance of elements on a Web page. Let’s look at both. You may define the settings parameter with a set duration (in milliseconds) or any of the words slow, normal or fast. The callback, which is the function that runs after the animation has finished, is optional.
Demo: Animate text
Run Demo View Code
Demo: Animate size
Easily change the size of a div.
Run Demo View Code
Demo: Animate movement
The .animate() function is asynchronous, so multiple animations may run at the same time. You can also use the .stop() function to stop the animation. If you click “Run demo” and then “Reset” during the animation, it will demonstrate the .stop() function.
Run Demo View Code
Many pure JavaScript functions are used frequently in animations, such as setInterval(), clearInterval(), setTimeout() and clearTimeout(). Once again, these functions are included in the list because understanding what they can do is important to supporting the jQuery’s animation functions.

setInterval() and clearInterval()

You can automate a task based on time using the JavaScript setInterval() function, which can be used to specify a regular time-based trigger.
Demo: Simple time counter
Click “Run demo” to start the timer, and click “Reset” to stop it.
Run Demo View Code
Demo: Digital time display
Run Demo View Code

setTimeout() and clearTimeout()

You can also delay a task based on time using the JavaScript setTimeout() function, which can be set to wait for a specified length of time before running the code.
Demo: Do something after a specified length of time.
Click “Run demo” to set the timeout and, click “Reset” to clear it.
Run Demo View Code

.slideToggle() and .fadeToggle()

jQuery provides various toggle functions that save us heaps of time when we want to bind related events to the same element. For example, .slideToggle() binds both .slideUp() and .slideDown() to the element and also manages that state for us.
Demo: Slide an element in and out of view.
Click “Run demo” to show the paragraph, and click again to hide.
Run Demo View Code
The .fadeToggle() function is similar to .slideToggle() but with a fading effect that uses the .fadeIn() and .fadeOut() methods.
Demo: Fade an element in and out of view.
Click “Run demo” to show the paragraph, and click again to hide it.
Run Demo View Code


In this demonstration, we’ll mainly use jQuery’s awesome function-chaining ability by running the .fadeOut(), .fadeIn() and .delay() functions together on the same element. This is very similar to the setTimeout() function we saw earlier but without allowing us to easily interrupt the delay.
Demo: Use .delay() to create a delay between function calls.
Run Demo View Code

jQuery And DOM Manipulation

The DOM (document object model) is all of the HTML content that you see on a website (text, images, container elements, etc.). We can use jQuery to perform wonders with the DOM when all page elements have been loaded. The event that captures when the DOM is ready is called .ready(), and there are a few ways to call it. In this section are demos of jQuery functions that change the DOM in some way.


The jQuery .clone() function is pretty simple to use; it basically just copies the element that you specify into a new element.
Demo: Clone an element.
Run Demo View Code

.html(), .text() and .empty()

Using .html() is the most common way to get or set the content of an element using jQuery. If you just want the text and not the HTML tags, you can use .text(), which will return a string containing the combined text of all matched elements. These functions are browser-dependent (i.e. .html() uses the browser’s innerHTML property), so the results returned (including white space and line breaks) will always depend on the browser you are using.
In this example, we are also making use of the .empty() function, which is a quick way to get rid of the content within, and .prev(), which can be used to reference the preceding element, in this case the demo buttons.
Demo: Get the content of an element.
Run Demo View Code

.append(), prepend(), .after() and .before()

These function provide the means of inserting content in particular places relative to elements already on the Web page. Although the differences may appear trivial, each has its own purpose, and knowing exactly where they will all place content will save you coding time.
Demo: Insert content onto a Web page.
Run Demo View Code

jQuery And AJAX

The jQuery library has a full suite of AJAX capabilities that enables us to load data from a server without refreshing the browser page. In this section, we will have a quick look at refreshing page content, loading scripts and retrieving data from different Web pages and servers.


The $.ajax() function is arguably the most used jQuery function. It gives us a means of dynamically loading content, scripts and data and using them on a live Web page. Other common uses are submitting a form using AJAX and sending data to server-side scripts for storing in a database.
The $.ajax() function has a lot of settings, and the kind team at jQuery has provided many shorthand AJAX methods that already contain the settings we require. Some developers like to write out the full AJAX settings, mainly because they require more options than many shorthand methods provide (such as beforeSubmit()). Also, note that you can use the Firebug NET.panel to analyze HTTP requests for testing, monitoring and debugging AJAX calls.
Demo: Use $.ajax() to load content without reloading the entire page.
For this demo, HTML content is held in separate files, which are inserted below using AJAX. Showing a loading icon while an AJAX request is processing is courteous. The third content block below has a two-second delay to simulate the loading icon.
Run Demo View Code
We can also use functions such as $.parseJSON() and JSON.parse() from ECMAScript5, which simplifies JSON parsing. If you’re interested in JSON parsing and tree recursion, see the “Online JSON Tree Viewer Tool.”


The .load() function is an AJAX shorthand method for inserting HTML straight into a matched element on the Web page.
Demo: Use .load() to grab HTML content from another Web page.
Run Demo View Code


AJAX requests are subject to the same origin policy, which means you may only send requests to the same domain. Fortunately, $.ajax() has a property named JSONP (i.e. JSON with padding), which allows a page to request data from a server on a different domain. It works by wrapping the target data in a JavaScript callback function. Note that the response is not parsed as JSON and may be any JavaScript expression.
Demo: Use AJAX and JSONP to load data from an external source.
This demo will load the latest pictures tagged “jQuery” from Flickr’s public feed.
Run Demo View Code
The AJAX shorthand functions $.getJSON and $.getScript and more AJAX examples can be found on my blog.

jQuery And Events

Managing events using regular JavaScript is entirely possible, however, jQuery provides a much more user-friendly interface to manage Web page events. Examples of such events are clicking a hyperlink, moving the mouse over an image and even pressing a key on the keyboard; the list goes on. Here are some examples of key jQuery functions that may be used to manage events.

.bind() and .unbind()

The .bind() function is very useful for adding event triggers and handlers to your DOM elements. In case you didn’t know, you can bind your DOM elements to a whole list of events, such as submit, change, mouseenter and mouseleave.
You may have also seen .click() used in jQuery code. There is no functional difference between .click() and .bind('click'), but with the latter we have the benefits of being able to specify custom events and add data parameters. There is also an .unbind() function to remove any events that have already been bound. As of jQuery 1.7 the .bind() function is an alias to .on() function. When you type in console: “jQuery.fn.bind.toString()” it will return: “function (a, b, c) { return this.on(a, null, b, c); }“.
Demo: Trigger an event when the user clicks on or hovers over a div.
Run Demo View Code
Demo: Trigger an event when the user hovers over or double-clicks a div.
Press “Run demo” a few times in a row for some nice effects. Also, double-clicking the boxes will make them disappear!
Run Demo View Code
Demo: Trigger an event when the user presses a key.
Press any key shown in the boxes below.
Run Demo View Code
Note: The key difference between keydown and keypress events is that the latter captures each individual character entered, as opposed to just firing once per key press. To illustrate, this simple tool shows the keycodes for any key that you press.

.live(), .on() and .off()

The .live() function is essentially the same as .bind(), but it can capture events on new elements that didn’t exist on the page when it was loaded; for example, if your Web page has loaded and then you dynamically insert an image onto it. If we used .bind() to attach an event when the mouse hovers over the image, it would not work. But if we used .live(), it would work! As of jQuery 1.7, you are advised to make use of the new .on() and .off() functions, instead of the .live() function, which has a few disadvantages to .on(). See “jQuery 1.7+ .on() vs. .live() Review” for a more detailed explanation of the differences.
Demo: Capture events on new or changed elements.
Click “Run demo” to dynamically insert more images and check that the event still fires on them.
Run Demo View Code


The .delegate() function provides a means of attaching event handlers to new elements (similar to the .live() function covered above). You might find .delegate() to be faster than .live() because the latter searches the entire document namespace for the elements as opposed to a single document. The much more important difference is that .live() is prone to break if used with traversing.
Demo: Delegate events to the child elements of a root element.
The demo area is the root element (orange border) with colored span child elements that have a hover event attached. Click “Run demo” a few times and hover with the mouse to trigger the effects.
Run Demo View Code


The .preventDefault() function can be applied to stop any element with a default action from firing: hyperlinks, keyboard shortcuts, form submit buttons, etc. These are probably the most common uses, and the function stops the hyperlink from going to its destination (the href). It’s very useful for stopping those default actions and running your custom JavaScript actions instead.
Demo: Prevent a hyperlink from going to its href.
Run Demo View Code


There are methods that do things similar to .preventDefault() but that behave differently. The .stopPropagation() function prevents the event from occurring on any ancestor elements. This can be used if you have an exception to the rule that you’ve specified for a container element with child elements. This function currently does not work with .live() events because it handles events once they have propagated to the top of the document.
Demo: Prevent a parent container from firing its event when its child is clicked.
Click both the link and div box area to see which event is fired.
Run Demo View Code


This function is nice for stopping all future bound events. The events will fire in the order they were bound, and when it hits the .stopImmediatePropagation() function, all further bound events are not fired.
Demo: Prevent all future bound events from firing.
Click both the link and div box area to see which event is fired.
Run Demo View Code

Finding, Looping And Filtering Results

jQuery gives us fast access to finding anything on the page and the ability to loop through or filter results as we please. It also has powerful functions to manipulate and extend data and functionality associated with JavaScript objects. There are so many things to cover in this section, so we have narrowed them down to a few key functions.

$.each() and .each()

There are two different methods for iterating with jQuery: .each() is used to iterate only over jQuery objects collections, while $.each() is a general function for iterating over JavaScript objects and arrays. I am a big fan of functions such as these and JavaScript shorthand techniques that provide us with a fast alternative to basic JavaScript coding.
Demo: Use $.each() to loop through values in an array.
Output the countries of the world (stored in an array).
Run Demo View Code
Demo: Use .each() to loop through DOM elements.
This demo loops through all of the h2 tags on this Web page and creates a table of contents.
Run Demo View Code
You can use $.each() and .each() on a lot of different things, such as DOM elements, arrays, objects and JSON. For those of you who are keen, you could try five more jQuery .each() examples.

$.data(), .data(), $.hasData() and $.removeData()

Updates to the jQuery library (mainly since 1.4) has brought the ability to attach data of any type to DOM elements. This is a very useful alternative to storing data in JavaScript objects and other such methods. There are two versions: $.data(), which takes in the element as a parameter, and .data(), which can attach directly to matched elements.
Note that $.data() returns a data object to the caller, whereas .data() does not. There are also many utility functions, such as $.hasData(), $.removeData(), that help with data management.
Demo: Attach data to DOM elements.
The following example sets and gets a data object into the div for this demo area.
Run Demo View Code

.match(), .test() and :contains()

Together with the jQuery :contains() selector, you can use the pure JavaScript functions .match() and .test() to save time when filtering for string values. Let’s look at some examples.
Demo: Extract email addresses from inside HTML (i.e. a string).
We can use .test() to check whether any emails are present, and use .match() to extract them.
Run Demo View Code
Demo: Use the jQuery :contains() selector to match elements with substrings.
We can use the :contains() selector to match substrings inside any of that element’s descendants (this is case sensitive).
Run Demo View Code


The .find() function is very useful for matching elements filtered by a selector, jQuery object or element. The .find() function can be used with the functions .children() (which searches only the direct child siblings of the matched elements) and .parents() (which searches the direct parent elements of the matched element).
Demo: Finde specific descendants of matched elements.
Run Demo View Code


The .filter() function allows us to reduce a set of matched elements based on a jQuery selector. This is useful when you want to process a group of elements and then further process specific child elements. The .filter() function can be used in a few different ways, such as to filter by a class name, function or jQuery object.
Demo: Use .filter() to match subelements.
In this example, .filter() is used to style paragraphs based on their content.
Run Demo View Code


The .slice() function lets us easily specify a subset of elements to perform actions on. It takes two parameters: start and end indices of subelements in a matched parent element.
Demo: Use .slice() to perform actions on a subset of elements.
Run Demo View Code

.prev() and next()

The .prev() and .next() functions can be used to reference the immediately preceding or next element in a set of matched elements (in the DOM hierarchy). You can also add a selector to the functions that acts as a filter on the elements (shown in the demo).
Demo: Reference the previous and next elements in a list.
Run Demo View Code


The $.extend() function can be used to combine two or more objects into the first object or into a completely new object.
$.extend( target, [object1,] [objectN] )
In the demo, we have a functional contact form on our website, and we want two more forms with similar functionality. Instead of copying all of the code that processes the form, we can use $.extend() to copy the functionality to our new forms, thus avoiding repetitive code. You might have noticed that the target element specified is a blank object; this is a trick that you will often see to create a new object of object1 and extend it with objectN (N representing any number of objects). So, in the example, we want to “copy” the existing functionality of forms.enquiry and simply override the email address.
Demo: Use $.extend() to change the send action on a form to different email addresses based on the form used.
This demo simulates the submission of three forms that all use the same code base.
Run Demo View Code
Demo: Use $.extend() to specify custom settings for a plugin.
This demo shows how to specify the length of paragraph excerpts. The default is 150 characters.
Run Demo View Code
Addy Osmani’s book Learning JavaScript Design Patterns gives greater insight into how to use the $.extend() function to override the default values of jQuery plugins.

.serialize() and .serializeArray()

The .serialize() and .serializeArray() functions can create string and array values from form fields in seconds! There are two demos here: the first outputs all of the form’s fields and their values, and the second creates a URL string with the form fields and values appended to the form action ready to be sent.

php email priority set in php mail function

$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=utf-8\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-MSMail-Priority: Normal\n";
$headers .= "X-Mailer: PHP/"."MIME-Version: 1.0\n";
$headers .= "From:" . $from . "\n";
$headers .= "Content-Type: text/html\n";
// Mail it

Saturday, January 19, 2013

Top PHP IDE for Open source Free

Top 8 PHP IDE for Website Developers (with Open source Free Options)

In order to get success in developing PHP sites it is necessary to have a good development environment. While producing web sites it is often necessary to edit HTML, CSS and JavaScript files. That is why usable IDE should supply all those file types and provide full set of tools for effective development.
This article includes list of some most popular PHP IDEs: Codelobster PHP Edition, Eclipse PDT, Komodo IDE, NetBeans IDE, PHPStorm, NuSphere PhpED.

Below are the best PHP IDEs in our opinion, (not necessarily in any order)

Codelobster PHP Edition

Codelobster PHP Edition is accessible from CodeLobster Software. CodeLobster PHP maintains Windows platform. Plug-ins are not free but the registration is absolutely free.
CodeLobster makes possible to install the debugger automatically. To get help how to configure the debugger, please, visit the official site. You have an ability to deploy projects on your local web server or remote server by FTP.
By downloading free version of the mentioned software you get PHP, HTML, JavaScript, and CSS code highlighting; JavaScript, HTML, PHP, and CSS code collapsing; HTML and CSS autocomplete; PHP and JavaScript Advanced autocomplete; HTML toolbar; Bookmarks; PHP Debugger; Context and Dynamic Help with search functionality for work with PHP, MySQL, HTML; Portable option; Pair highlighting; Pair selection, tags and attributes selection commands; Tooltip; Navigation by holding CTRL key; HTML/CSS code inspector; Class View; Project manager; Preview in a browser; File Explorer with FTP/SFTP support; Incremental find and other possible functionalities of similar programs.
These plug-ins allow operating with famous CMS and Frameworks: Facebook, CakePHP, Joomla, WordPress, Drupal, Smarty, JQuery, Symfony, CodeIgniter, Yii.

Eclipse PDT

Eclipse is designed to allow developers to choose language, platform, and vendor environment. Eclipse Platform includes wide range of plug-ins, tools, and examples. Eclipse is a program that makes available to construct, integrate, and use software tools.
Supported operating systems: Linux, Windows and Mac OS X.
Installation includes all necessary tools to elaborate on PHP. It also involves Data Tools Platform to control the databank, plug-ins for interaction with JavaScript, C / C + +, XML editor, and other different tools. You can use Zend debugger or Xdebug for Debugging PHP applications on Eclipse PDT.

Komodo ActiveState

Komodo ActiveState is a PHP IDE that can be used as an international language development environment and supply Ruby, Perl, and Tcl Python. It can be installed using of Smarty and Zend PHP frameworks. You can also use integration involving version control systems (CVS, Subversion and Perforce).
Supported operating systems: Linux, Windows and Mac OS X.
Komodo allows you to begin CGI Environment Simulation and construct web server holodeck. It simulates activities in a real web server. One of the advantages of CGI Environment Simulation is very fast installation. It is possible to download free 21-day version of Komodo from ActiveState site.


PhpStorm provides qualitative and rich facilities for PHP code editing including highlighting, conformation of code formatting, fast error checking, intensive code autocomplete.
PhpStorm editor is compatible with PHPDoc in your code and provides appropriate code ending based on proprietary, device and var annotations. PHP code refactoring also reviews PHPDocs to keep them up-to-date.
Supported operating systems: Linux, Windows and Mac OS X.
PhpStorm is focused on developer’s productive capacity that profoundly co-operates your code, assures smart code ending, quick navigation and very fast error checking. It will help you to form your code, run unit-tests or perform full debugging.
PhpStorm is an IDE for HTML, JavaScript and PHP. PhpStorm code ending functionality (Ctrl + Space) completes classes, functions, variable names, PHP keywords, and besides often used names for fields and variables depending on their types.

NuSphere PhpED

NuSphere PhpED works on Windows environment. If NuSphere is certificated you can use IDE with OS MAC or Linux via Wine emulator.
Supported operating systems: Windows 2000, XP, 2003, 2008, Vista, Windows7.
PhpED is provided with Advanced PHP Editor, PHP Debugger and PHP Profiler, Code Insight, Database Client, Integrated Help System, Code Insight. It completely supports JavaScript, HTML, CSS, XML, SMARTY, XHTML and others. IDE maintains PHP from 4.2 to 5.3 version and the Editor - from features and variables to spaces and aliases, Dynamic Syntax Highlighting, Multiple Language Syntax Highlighting, Auto Highlight variables etc.
IDE PhpED provides customers with a lot of tools and features useful for elaboration on PHP. There is a database management client, separate window to manage Telnet or SSH connections, NuSOAP window to work with web services. PhpED supports its own embedded web server adjusted in IDE, but the server is available for small applications only. Full web applications should be adjusted on outer web server. Debuggers PhpED, DBG can interact with apache, IIS, web server which maintains standard PHP utilization.

Zend Studio

Zend Studio is one of the very comprehensive PHP IDE available. It has very powerful PHP and Javascript debugging, team collaboration and remote server tools. The Zend studio is one of the highest priced PHP IDEs, though it has a free version however that does not come with very good features.

+2 Open Source Free PHP IDEs

NetBeans IDE(Free)

Elaboration of NetBeans IDE is performed by independent NetBeans community and NetBeans Org Company. Oracle maintains and invests in NetBeans IDE.
Program allows editing several files at once by dividing screen into several parts. In order to do it, you need to open two files and drag a marker of any file to the bottom of the screen. Then you can see a red framework in text box in the lower part of screen.
Supported operating systems: Linux, Windows and Mac OS X.
All the tools necessary for construction of professional desktop, web, and mobile applications with the Java platform, C/C++, PHP, JavaScript and Groovy are accessible. A library of free source codes is integrated for software developers. NetBeans IDE 7.0, produced with language supporting to elaborate on Java SE 7, supports GlassFish 3.1, Oracle Database, Maven 3, Oracle WebLogic, HTML 5.

Aptana Studio PHP Editor(Free)

Aptana Studio, Developed by Aptana Inc. is a leading open-source HTML editor and many people are not aware that it also comes with a PHP support. Aptana Studio is developed on Eclipse platform.
Supported operating systems: Linux, Windows and Mac OS X.
It has in built support for Smarty and the recent versions for Aptana also include a Debugger for PHP developers. Aptana Studio is built on top of Eclipse platform and is very stable and powerful.


Most of IDEs have the opportunity to add and parse any library or framework. After this well-read work autocomplete feature works for the corresponding classes. However Codelobster PHP Edition, thanks to a special plug-in, has a possibility to create PHP projects using many open source PHP frameworks automatically, add new modules and components, look-ahead Templates in special Theme Editor and serve Context with help original sites. The choice is yours!

There are a number of other productivity PHP IDEs too, besides the ones mentioned. Do let us know if you have used some other tools or plug-ins which you were impressed with.

Friday, January 18, 2013

ms excel/csv data import into mysql php example

$host="localhost"; // Host name.
$db='myDB'; // Database name.
$conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
mysql_select_db($db) or die (mysql_error());

echo $filename=$_FILES["file"]["name"];

$file = fopen($filename, "r");
         while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
            $sql = "INSERT into myTable(name,address,email,password) values('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]')";
         echo "CSV File has been successfully Imported";
echo "Invalid File:Please Upload CSV File";

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import CSV/Excel file</title>
<form enctype="multipart/form-data" method="post">
<table border="1" width="40%" align="center">
<tr >
<td colspan="2" align="center"><strong>Import CSV/Excel file</strong></td>

<td align="center">CSV/Excel File:</td><td><input type="file" name="file" id="file"></td></tr>
<tr >
<td colspan="2" align="center"><input type="submit" value="Import"></td>

fetchCsv.php file will upload the CSV/Excel file and imort the file into Mysql Database.
If you face any problem than let me know via comment .

Wednesday, January 16, 2013

How to fix PHP wordpress,joomla,cakephp,codeingiter, upload file inherit permissions error using Windows IIS Server

How to fix PHP like wordpress,joomla,cakephp,codeingiter,zend,opencart,magento, upload file inherit permissions error using Windows IIS Server "SOLVEED"

If you’re like me, and you use Windows IIS, you’ve spent hours trying to figure out why your uploaded file won’t inherit the permissions needed to display correctly.  Luckily, the answer is extremely easy and something most people would have never thought of.
The problem only happens when you use PHP to upload a file.  When you upload a file, PHP sends the file to a temporary directory on the hard drive (for me it is C:\Windows\Temp) and then copies it over to it’s intended directory.  Once the file has landed in the temporary directory, it is assigned the permissions of that directory. The problem is when Windows copies that file, it keeps the temporary directory’s permissions and doesn’t inherit your web directory’s permissions.
The easiest way to fix this problem is to add to the temporary directory your intended web directory’s permissions.  There’s no need to erase the permissions already in the temporary directory, just add the web directory’s permissions to them. In other words, follow these steps
  1. To change the permissions of your temporary upload directory, find the “upload_tmp_dir” in your php.ini file.
  2. Set it to the directory of your choosing (outside your web folders of course) or leave it at default (for me it is C:\Windows\Temp).
  3. Browse to this folder and add the permissions of your web folders to it.
That’s it!  As you can see, its really simple and just a little trick the guys at PHP forgot to tell us.
And just so you know, if the two folders were on separate drives, you wouldn’t have this problem, and thus wouldn’t be reading this.