Header menu

_________________________________________________________________________________

Tuesday 30 September 2014

Auto-click function for facebook login button using javascript


  

Auto-click function for  facebook login button using javascript

(Function to initialize facebook login process)


I have added facebook sign button on my website. On clicking on it i can make user to login in my application using facebook account.

Now i want to click on some other button and want to initialize facebook login functionality .

To do so i need 2-3 lines of code / a function to start login process.

function facebookLogin() {
    FB.login(function(response) {
        if (response.authResponse) {
        statusChangeCallback(response);
        //    console.log('Authenticated!');
            // location.reload(); //or do whatever you want
        } 
    },
    {
        scope: 'email,user_checkins'
    });
}
facebookLogin();


Auto-click function for google sign button using javascript


  

Auto-click function for  google sign button using javascript

(Function to initialize google sign process)

I have added google sign button on my website. On clicking on it i can make user to login in my application using google account.

Now i want to click on some other button and want to initialize google sign functionality .

To do so i need 2-3 lines of code / a function to start login process.

var myParams = {
    'clientid': 'your client-id',
    'cookiepolicy': 'single_host_origin',
    'callback': 'onSignInCallback',
    'scope': 'email'
};
gapi.auth.signIn(myParams);



Saturday 9 August 2014

Ajax Simple Captcha on jquery Dialog form


 

Ajax  Simple Captcha on jquery Dialog form

CAPTCHA  is a type of challenge-response test used in computing to determine whether or not the user is human. Adding captcha to html/php page is simple task . But its not so easy in jquery dialog form for newbies . So lets implement a simple captcha for jquery dialog form.

I will use 4 files :
1. index.php ( Contains html form, javascript code to send ajax request)
2. captcha.php ( Create captcha image)
3. captcheck.php ( Check weather value entered for captcha is right or wrong)
4. post.php ( Page where form submits if captcha validation is fine)
index.php

Friday 25 July 2014

Table data overflowing even after giving fixed width due some long string .


 

Table data overflowing even after giving fixed width due some long string .

After giving fixed width to table and column ,we suppose that we will get same type of table every time. But sometime due to some long string which is greater than width of column , table overflows of given width.

To tackle that problem add these two small lines to your style:



Firstly , give fixed layout out to table and secondly add word-wrap: break-word; property to column . And you are all done :)

Tuesday 27 May 2014

Extract parameters from url using javascript or jquery in html file.


 

Parsing url in jquery or javascript to extract parameter from url in html file


If you are using a html file and you have to receive some parameters from url , then
below is the method you are looking for.

Only this you have to do ... is to call getUrlVars with field name to extract as done in this statement  :

var first_name = getUrlVars()["first_name"];  


Tuesday 20 May 2014

In how ways you can add css to a html page ?


 

Methods to add css to html page :

We can add css to a page using 3 methods :

a) External css
b) Internal css 
c) Inline css 

External css : In this we make an css file and then call that file in our page using link .
      

Internal css : In this we write our css in head of the the html page using style tag.
               

Inline css : In this we add style to the element . 

The best method of adding css is external and the most powerful is inline because override    previous css included.

Thursday 15 May 2014

Use of RedirectMatch 301 directive in htaccess.


 

Use of  RedirectMatch 301 directive in htaccess.

To redirect more than a single page using htaccess, you can use the "RedirectMatch 301" directive, which allows you to specify directory matching patterns using regular expressions.

Here  301 redirect is a permanent redirect method which passes between 90-99% of  ranking power to the new redirected page and (?i) signifies case insensitivity .

Point to remember:

1. (?i) starts case-insensitive mode
    (?-i) turns off case-insensitive mode

2.  /directory/cart   This is the directory which i am redirecting . When this directory structure will occur in url , page will be redirected to stated page.

3.   http://localhost/directory2?   This is my new address where i want page to be redirected.

Wednesday 14 May 2014

Jquery not loading properly on clicking links in mobile site.


 

Jquery not loading properly on clicking links in mobile site.

Today while working on a mobile site , i went through a strange problem. Everything works well on site when i refresh page but when i click on links then my jquery and css are not loading properly. Resulting in improper design. After searching about the problem i came to know that on mobile jquery loads only on first page on all other pages its use preloaded js and css.

More you can read at : http://demos.jquerymobile.com/1.2.1/docs/pages/page-scripting.html

Now to solve this problem . I added rel='external'  to every link . Now whenever i click on link my jquery and css are loading properly.

Tuesday 6 May 2014

How to get value of select box in Javascript/Jquery ?


 

Get value of select box in Javascript/Jquery

This is my select box.  And i want to get its value in javascript/jquery .

<select name="qt" class="qt" id='qt'>
<option value='0'>&nbsp;</option>
<option value='Newspaper'>Newspaper</option>
<option value='Facebook Ad'>Facebook Ad</option>
<option value='Google Search'>Google Search</option>
<option value='Other Internet Site'>Other Internet Site</option>
<option value='Test Prep Center'>Test Prep Center</option>
</select>

 To get its value i will use two lines.

var s = document.getElementById('qt');         /**qt is the id of select box**/
var selectval = s.options[s.selectedIndex].value; 

Working example:

Friday 2 May 2014

PHP force file download method not working on android mobile when file path is passed from database


 

PHP force file download method not working on android mobile when file path is passed from database

When you use are using force download method of php to download some music/video on any android device ( I specifically performed for this ) . Then you might face two types of problems.

1.  You will get html page instead of media file.

2.  When you are passing file path from database, your file is not downloaded completely. It will show download complete after downloading some byte. In straight incomplete file is downloaded .

Below is the code that will work for solving these two problem. The points to remember are 

(a) Do not call download method from the loop where you are checking post or get request . Call download method out of GET/POST condition check loop. It is solve first problem of html pages download.

(b) Pass only file name from the database . Keep the file path static . I know this will make code hard coded but if you pass path from database then '/'  in path will create problem. And you will not be able to download file properly.



                                                I hope this will work for you too ..  :)

Sunday 27 April 2014

Facebook javascript SDK returns undefined email in response


 

Facebook javascript SDK returns undefined email in response

Yesterday ,i was implementing login through Facebook option on my website . Initially everything went well . Then with no reasons facebook started returning undefined email ids.

If you are facing the same problem too , then there is two words solution for this . Add data-scope="email" in button.


Facebook javascript SDK returns undefined email in response

                                               I hope this will work for you too ..  :)

Monday 21 April 2014

Javascript autosubmit form Error: submit() is not a function



 Submit() is not a function. 

 

This error occurs in javascript while auto submitting form when there exist an input field with name submit or input of the type submit in the html form.

To remove the error just change the name from submit to something else .Then your form will work flowless.

 

Error :


Form  giving error:



Corrected Form: [name submit removed]


Friday 11 April 2014

InnoDB: mmap(137363456 bytes) failed; errno 12



* Error displaying the error page application instantiation error

* Error happens while site is running and mysql database  crashes . On reboot everything start working well again.

  Error logs

140410 9:16:44 [ERROR] Native table 'performance_schema'.'file_instances' has the wrong structure 140410
9:16:44 [Note] Event Scheduler: Loaded 0 events 140410 9:16:44 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.29-0ubuntu0.12.04.2' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Ubuntu) 140410 21:26:53 [Note] Plugin 'FEDERATED' is disabled.
140410 21:26:53 InnoDB: The InnoDB memory heap is disabled
140410 21:26:53 InnoDB: Mutexes and rw_locks use GCC atomic builtins 140410 21:26:53 InnoDB: Compressed tables use zlib 1.2.3.4
140410 21:26:53 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12
 140410 21:26:53 InnoDB: Completed initialization of buffer pool
140410 21:26:53 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140410 21:26:53 [ERROR] Plugin 'InnoDB' init function returned error.
140410 21:26:53 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140410 21:26:53 [ERROR] Unknown/unsupported storage engine: InnoDB 140410 21:26:53 [ERROR] Aborting
140410 21:27:08 [Note] Plugin 'FEDERATED' is disabled.
140410 21:27:08 InnoDB: The InnoDB memory heap is disabled
140410 21:27:08 InnoDB: Mutexes and rw_locks use GCC atomic builtins 140410 21:27:08 InnoDB: Compressed tables use zlib 1.2.3.4
140410 21:27:09 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12
140410 21:27:09 InnoDB: Completed initialization of buffer pool
140410 21:27:09 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140410 21:27:09 [ERROR] Plugin 'InnoDB' init function returned error.
140410 21:27:09 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140410 21:27:09 [ERROR] Unknown/unsupported storage engine: InnoDB 140410 21:27:09 [ERROR] Aborting 140410 21:27:09 [Note] /usr/sbin/mysqld: Shutdown complete
140410 21:27:10 [Note] Plugin 'FEDERATED' is disabled.
140410 21:27:11 InnoDB: The InnoDB memory heap is disabled
140410 21:27:11 InnoDB: Mutexes and rw_locks use GCC atomic builtins 140410 21:27:11 InnoDB: Compressed tables use zlib 1.2.3.4
140410 21:27:11 InnoDB: Initializing buffer pool, size = 128.0M
InnoDB: mmap(137363456 bytes) failed; errno 12
140410 21:27:11 InnoDB: Completed initialization of buffer pool
140410 21:27:11 InnoDB: Fatal error: cannot allocate memory for the buffer pool
140410 21:27:11 [ERROR] Plugin 'InnoDB' init function returned error.
140410 21:27:11 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
140410 21:27:11 [ERROR] Unknown/unsupported storage engine: InnoDB 140410 21:27:11 [ERROR] Aborting 

This error might occur in InnoDB in two situation :

1. When InnoDB unable to allocate memory as specified in innodb_buffer_pool_size variable




And then reboot the system. If your problem is not solved by these steps , then look for you swap file.

2. Swap file not present .If swap file is not present you can create it by

Wednesday 2 April 2014

Pass parameter to post method of file_get_contents()


If you are looking for some alternative to php cURL then file_get_contents is the function you are looking for. File_get_contents() is the  way to read the contents of a file into a string. We are going to discuss this function  as simple one to request data from server and then with post method to parameters requesting for some specific content. It is same as like CURL requesting server/service for some data.

In simplest form we can just pass url to function to get content of webpage:


To do more you can pass parameter as string to post method



At last passing array as parameter to post method of file_get_contents()

Wednesday 5 March 2014

How to create Fixed left sidebar in html ?


To create a fixed left sidebar in html we need to make its position fixed in css and float left so that sidebar remain left aligned.

 float:left;
 position:fixed; 

These two lines will do the magic for you. To understand more run the below example:


<html>
           <head>

                      <style>
                                 .left-sidebar{
                                                        float:left;
                                                        position:fixed;
                                                        width:200px;
                                                        background-color:#47D7ED;
                                                     }
                                 .left-sidebar p {
                                                         width:700px;
                                                         text-align:justify;
                                                      }
                                 .container1{
                                                        position:relative;
                                                        width:84%;
                                                        background-color:#FFFFFF;
                                                        border:1px solid;
                                                        min-height:1500px;
                                                        height:auto;
                                                        margin-left: 205px;
                                                      }
                         </style>
            </head>
<body>
           <div class='left-sidebar' id='left-sidebar'>
                     <ul>
                            <li id='li-banner'>Banners</li>
                            <li id='li-banner1'>Banners</li>
                           <li id='li-banner2'>Banners</li
                     </ul>
             </div>
             <div id='container' class='container1'>
                      <h1>My Left Side bar is fixed.</h1>
                      <h1>Its not gonna move :)</h1>
             </div>
</body>
</html>


Monday 3 March 2014

Highlight/Blink effect using jquery



We often use blink in html to get users attention but it makes our info unreadable and irritating. So today i am sharing a small jquery code which will produce same effect. And can be easily edit according to need.


 function blink(){
      $("#box").fadeTo(100, 0.1).fadeTo(200, 1.0);
      }
 self.setInterval(function(){blink()},1000);

This is small code which can do the whole thing work. Self.setInterval() is function which will call itself after 1 sec and call blink function. 

For more details run the below example : 

Saturday 1 March 2014

Iteration through array with delay in jquery


What my problem is I have an array and i have to pass array element to some function with some delay between each call. Now if i iterate using loop the iteration has already been completed before calling function and i am only able to pass last value of my array to function. To deal with this i found a way using recursion such that there is delay between my each call to function.

Now in my example :
l is length of array
arr is array
k is index
tex is my function i am calling

Example:


 var k=0;
 var arr=[1,2,3,4,5,6,7,8];
 function tex(arr,k,l){
                    if(k<l){ 

                                 alert(arr[k]);
                                 setTimeout(function() { k++; tex(arr,k,l); },3000);
                               }
                }
  tex(arr,k,8);    


This is basic structure of code and it will call tex() after each 3 sec and tex will alert array elements one by one.

To understand more run below example:

Wednesday 26 February 2014

How to create a link on button tag in html ?


Button with link

Sometimes we need to create link on button in html . To do so we just need to add button tag on text of <a> tag.

In below line of code we have applied <button> tag on text of <a> tag.

<a href="http://www.codesplanet.blogspot.com" target="_parent"><button>Click me !</button></a>

Now we have a button with link on it 

Thursday 20 February 2014

Close button not showing on jquery ui dialog form


This problem might occur when you call jquery ui css file local system. The problem is your script is able to findat provided url given in css file. To fix the error you need to made change to two lines in css file.
Change the text with in red  at line number 823 and 840 with

http://1.bp.blogspot.com/-IngEXFSQ2y0/UwYnr4vsTGI/AAAAAAAAAMY/iHmyu11rGCM/s1600/close.gif

Corrected statement will be :

background: #dadada url(http://1.bp.blogspot.com/-IngEXFSQ2y0/UwYnr4vsTGI/AAAAAAAAAMY/iHmyu11rGCM/s1600/close.gif ) 50% 50% repeat-x;
1. At line number 823

.ui-widget-header .ui-state-default {
border: 1px solid #d3d3d3;
background: #e6e6e6 url(images/ui-bg_glass_75_e6e6e6_1x400.png) 50%   50% repeat-x;

font-weight: normal;
color: #555555;
}
2. At line number number 840
.ui-widget-header .ui-state-focus {
    border: 1px solid #999999;
    background: #dadada url(images/ui-bg_glass_75_dadada_1x400.png) 50% 50% repeat-x; 
     font-weight: normal;
    color: #212121;
}


Saturday 15 February 2014

Multiple file upload with form submit using ajax


File upload  in ajax form is always a headache to newbie. Today i am sharing a simple tutorial to upload files in ajax. What you have to do is ,just copy two files one containing form and other receiving posted data and run them .I have tried it to keep it simple so please ignore the design.

form.php
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://github.com/malsup/blockui/raw/master/jquery.blockUI.js?v2.31"></script>
<script type="text/javascript" src="http://github.com/malsup/form/raw/master/jquery.form.js?v2.36"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('form').ajaxForm({
    });
    $("#add_file").on("click",function(){
        var ranNum = Math.round(Math.random()*50);
        $("#fileone").append("<div id='file"+ranNum+"'><input type='file' name='file"+ranNum+"' /><button type='button' class='rem' id='rem_file"+ranNum+"'>X</button></div>");
        p_id=ranNum;
    });
    $(document).on("click",".rem",function(){
        var id=$(this).attr('id');
        var ret = id.split("_");
        $("#"+ret[1]).remove();
    });   
});
</script>

Thursday 6 February 2014

An array contains number from 1 to 10 . One number is missing. Find the number missing with O(n) complexity.

<?php
  $arr=array(10,1,4,5,7,8,9,3,2);
  $sum=0;
  for($i=0;$i<=10;$i++){
      $sum=$sum+$i;
    }
   $newsum=0;
  foreach($arr as $arr){
      $newsum=$newsum+$arr;
    }
  $missingnumber=$sum-$newsum;
  echo  $missingnumber;
?>

Explain difference between delete, truncate and drop command in Mysql.

 DELETE

DELETE command in mysql is used to remove rows from a table. We can use where clause  to only remove some rows. If we do not  specify any where clause , all rows will be removed.DELETE operations can be rolled back.
 Syntax : DELETE FROM table_name WHERE column_name=value;

TRUNCATE

TRUNCATE command in mysql removes all rows from the table. The operation cannot be rolled back and no triggers will be fired.  TRUNCATE is faster than DELETE.
Syntax:  TRUNCATE TABLE table_name;

DROP

The DROP command in  mysql removes the table from the database. All the table rows, indexes and privileges will  be removed. No triggers will be fired and the operation cannot be rolled back.
Syntax:  Drop TABLE table_name;

Point to note :
 DELETE operations can be rolled back on the other hand  DROP and TRUNCATE operations cannot be rolled back.

Tuesday 4 February 2014

Stop/Hold output before sending of header


ob_start()

Normally, the output  starts as soon as your first "echo" comes  or first non-PHP content. Once output starts, we cannot send headers . So to tackle this we use output buffering we is disabled by default.  

To create a new output buffer and start writing it, we call ob_start(). There are two ways to end a buffer :-

1.  ob_end_flush()
      It ends the buffer and sends all data to output

2.  ob_end_clean()
      It ends the buffer without sending it to output.

Consider the following script:

<?php
    ob_start();
    echo
"Hello One!\n";
    
ob_end_flush();

    
ob_start();
    echo
"Hello Two!\n";
    
ob_end_clean();

    
ob_start();
    echo
"Hello Three!\n";
?>

Output :  Hello One! Hello Three!

This script will output "Hello One" because the first text is placed into a buffer then flushed with ob_end_flush().

The "Hello Two" will not be printed out, although it is echoed, because it is placed into a buffer which is cleaned using ob_end_clean() and not sent to output.

Finally, the script will print out "Hello Three" because PHP automatically flushes  output buffers when it reaches at the end of a script.

Monday 3 February 2014

Inner join between more than two tables


Inner Join between more than two tables

To explain this lets take an example.
We have three table table1,table2,table3 .
table1 has primary key pk on which we want to take join of three table.

Query :  

SELECT * FROM table1
INNER JOIN table2 ON table1.pk=table2.table1Id
INNER JOIN table3 ON table1.pk=table3.table1Id

Friday 24 January 2014

Set a cookie / Use a cookie / Discuss a cookie / Explain Cookie


How to set a cookie.

Use setcookie() for setting a cookie.

Example : setcookie('flavor','vanilla');

Calling setcookie()

Cookies are sent with the HTTP headers, so setcookie() must be called before any output is generated. 

Use a Cookie

<?php
// Print an individual cookie
echo $_COOKIE["flavor"]; ?>
 


Arguments to setcookie()

You can pass additional arguments to setcookie() to control cookie behavior. The third argument to setcookie() is an expiration time,expressed as an epoch time- stamp.

Example setcookie('flavor','vanilla',1202075201);

Sunday 19 January 2014

Best collection of php interview questions with answer for freshers


ANY SUGGESTION , QUESTION or CORRECTION is heartly welcome ... 


Ques 1. How can I disable the output of error message inside a HTML page?

Ans. Use  error_reporting(0);  to hide the error message in output.


Ques.2 Can we return other file formats (like Word, Excel, etc) using PHP script?

Ans. Yes we can create and return file formats(like Word, Excel etc) using php script.


Ques.3 Why we use session variable ?

Ans.  When we work on an application, we open it, do our stuff and then we close it. This is much like a (time interval)Session. The computer knows who we are. It knows when we started the application and when we ended it. But on the internet there is a problem,  web server does not know who we are and what we do. Because the HTTP address does not maintain state.
A PHP session solves this problem by allowing us to store user information on the server for later use (i.e. username, place,email id etc). However, session information is temporary and will be deleted as soon as the user has left the website. If we need a permanent storage then we have to store the data in a database.


Ques.4 Explain PEAR in php ?

Saturday 18 January 2014

How to get my ubuntu version ?

To know which version of ubuntu you are using , you can use two ways :-

1. Using Terminal

2. Using Interface

Using Terminal

To know your ubuntu version through terminal use lsb_release -a


Using Interface

To know  your ubuntu version using interface first click on system setting from top right corner of the desktop


then after click on details ..


Friday 17 January 2014

Difference between various types of join in SQL


Assuming you're joining on columns with no duplicates, this the most common case:
  • An inner join of table One and Two gives the result of One intersect Two, i.e. the inner part of a venn diagram intersection.
  • An outer join of One and Two gives the results of One union Two, i.e. the outer parts of a venn diagram union.

Examples
Suppose you have two Tables, with a single column each, and data as follows:
One     Two
-     -
1     3
2     4
3     5
4     6

Note that (1,2) are unique to One, (3,4) are common, and (5,6) are unique to Two.


Inner join
An inner join using either of the equivalent queries gives the intersection of the two tables, i.e. the two rows they have in common.
select * from One INNER JOIN Two on One.One = Two.Two;


One  | Two

3  | 3
4  | 4

Wednesday 15 January 2014

Explain difference between include , require and require_once in php ?


To include the content of a PHP file into another PHP file before the server executes it. There are three PHP functions which can be used to include one PHP file into another PHP file.
  • The include() Function 
  • The require() Function
  • The require_once() Function
These functions helps in creating functions, headers, footers, or elements that can be reused on multiple pages. This help developers to change the layout of complete website with minimal effort. If there is any change needed then instead of making change in large numbers of files just change included file.

The include() Function

The include() function copies all text from file which is passed as parameter into the file that uses the include function. If there is any problem in loading thefile then the include() function generates a warning but the script will continue execution.