Wednesday, 26 July 2017

Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape?

If using JavaScript then:
<script>
$('#myModal').modal({
    backdrop: 'static',
    keyboard: false
})
</script>
and if HTML:

<a data-controls-modal="your_div_id" data-backdrop="static" data-keyboard="false" href="#">

Monday, 10 July 2017

short code for js in netbeans shortcut

Code 1:  

Type sc and press enter for script code 

Output:

<script type="text/javascript">      </script>

Code 2: 

Type d and press enter for document ready 

Output: 

<script type="text/javascript">
     $(document).ready(function(e) {   

       });
 </script>

Code 3: 

Type p and press enter for ajax post 

Output:

<script type="text/javascript">    
 $(document).ready(function (e) {  
       var post_data = {};       
        $.post("", post_data, function (res) {   
       });  
   }); 
</script>

Monday, 3 July 2017

Click button copy to clipboard using jQuery

 

// html code here 


<div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <br/>
                <h3 class="text-center">Capture Feedback</h3>
                <br/>
                <div class="col-md-8 col-sm-8 col-xs-12 col-md-offset-2 col-sm-offset-2">
                    <div class="col-md-8 col-sm-8 col-xs-12">
                        <input type="text" class="custom-url" placeholder="company rating link" value="https://www.google.co.in/" name="" id="copyTarget">
                    </div>
                    <div class="col-md-4 col-sm-4 col-xs-12">
                        <button class="custom-url color-red" id="copyButton">Copy URL</button>
                    </div>

                </div>
            </div>

        </div>

// Script code here 


<script type="text/javascript">
 document.getElementById("copyButton").addEventListener("click", function() {
    copyToClipboard(document.getElementById("copyTarget"));
    alert("Text copied");
});

function copyToClipboard(elem) {
 // create hidden text element, if it doesn't already exist
    var targetId = "_hiddenCopyText_";
    var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
    var origSelectionStart, origSelectionEnd;
    if (isInput) {
        // can just use the original source element for the selection and copy
        target = elem;
        origSelectionStart = elem.selectionStart;
        origSelectionEnd = elem.selectionEnd;
    } else {
        // must use a temporary form element for the selection and copy
        target = document.getElementById(targetId);
        if (!target) {
            var target = document.createElement("textarea");
            target.style.position = "absolute";
            target.style.left = "-9999px";
            target.style.top = "0";
            target.id = targetId;
            document.body.appendChild(target);
        }
        target.textContent = elem.textContent;
    }
    // select the content
    var currentFocus = document.activeElement;
    target.focus();
    target.setSelectionRange(0, target.value.length);
   
    // copy the selection
    var succeed;
    try {
     succeed = document.execCommand("copy");
    } catch(e) {
        succeed = false;
    }
    // restore original focus
    if (currentFocus && typeof currentFocus.focus === "function") {
        currentFocus.focus();
    }
   
    if (isInput) {
        // restore prior selection
        elem.setSelectionRange(origSelectionStart, origSelectionEnd);
    } else {
        // clear temporary content
        target.textContent = "";
    }
    return succeed;
}
</script>

Friday, 30 June 2017

Client Side Validation in Ckeditor or CKeditor Validation

Note: include JQuery  file and JQuery validation files

STEP NO : 1

<form action="#" method="post" id="formId">
<label>Description</label><textarea name="blog_description" class="required" id="editor1"></textarea>
            <script>
                CKEDITOR.replace('editor1');
            </script>

<input name="submit" type="submit" value="Submit Job" class="button" id="job-submit"/>
<input name="clear" type="reset" value="Clear Form"  class="button"/>
</form>

Thursday, 22 June 2017

How to get post image in worpdress or How to get post thumbnail in wordpress

//Default WordPress


// Thumbnail (150 x 150 hard cropped)


<?php    the_post_thumbnail( 'thumbnail' );       ?>

// Medium resolution (300 x 300 max height 300px)  
<?php the_post_thumbnail( 'medium' ); ?>  

 // Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)    
<?php the_post_thumbnail( 'medium_large' ); ?> 

// Large resolution (1024 x 1024 max height 1024px)
<?php the_post_thumbnail( 'large' );  ?>    

// Full resolution (original size uploaded)
<?php the_post_thumbnail( 'full' );  ?>      


//With WooCommerce


// Shop thumbnail (180 x 180 hard cropped)


<?php the_post_thumbnail( 'shop_thumbnail' ); ?>  

// Shop catalog (300 x 300 hard cropped)
<?php the_post_thumbnail( 'shop_catalog' );  ?>   

 // Shop single (600 x 600 hard cropped)
<?php the_post_thumbnail( 'shop_single' ); ?>    

Tuesday, 20 June 2017

How to change dynamic background color

Script for change background color : Dynamic color 


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script>
    jQuery(function ($) {
        function changeColor(selector, colors, time) {
            var curCol = 0,
                    timer = setInterval(function () {
                        if (curCol === colors.length)
                            curCol = 0;
                        $(selector).css("background", colors[curCol]);
                        curCol++;
                    }, time);
        }
        $(window).load(function () {
            changeColor("#wrap", ["linear-gradient(to right, rgb(241, 242, 181), rgb(19, 80, 88))", "linear-gradient(to right, rgb(209, 145, 60), rgb(255, 209, 148))", "linear-gradient(to right, rgb(254, 172, 94), rgb(199, 121, 208), rgb(75, 192, 200))", "linear-gradient(to right, rgb(123, 67, 151), rgb(220, 36, 48))","linear-gradient(to right, rgb(112, 225, 245), rgb(255, 209, 148))","linear-gradient(to right, rgb(64, 59, 74), rgb(231, 233, 187))","linear-gradient(to right, rgb(58, 28, 113), rgb(215, 109, 119), rgb(255, 175, 123))","url('https://www.planwallpaper.com/static/images/Seamless-Polygon-Backgrounds-Vol2-full_Kfb2t3Q.jpg')"], 3000);
        });
    });
</script>

Monday, 19 June 2017

Only show current month of post in wordpress

<?php $current_month = date('m'); ?>

<?php $current_year = date('Y'); ?>

<?php query_posts("monthnum=$current_month&year=$current_year") ?>

<?php if ( have_posts() ) : ?>

<?php while ( have_posts() ) : the_post(); ?>

<?php the_content(); ?>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

Wednesday, 10 May 2017

Make div 100% height of browser window

How can this be used to make a divider fill the height of the browser?


For this question, we can make use of vh: 1vh is equal to 1% of the viewport's height. That is to say, 100vh is equal to the height of the browser window, regardless of where the element is situated in the DOM tree:

HTML
<html>
<head>
<title>Make div 100% height of browser window <title>
</head>
<div> </div>
<html>

CSS
<style>
div {
    height:100vh;
background:#ddd;
}
</style>

Tuesday, 18 April 2017

How to change the color of header bar and address bar in mobile (Responsive )

You need to add a <meta> tag in your <head> containing name="theme-color", with your HEX code as the content value.   For example:
<meta name="theme-color" content="#999999" />

You actually need 3 meta tags to support Android, iPhone and Windows Phone
<!-- Chrome, Firefox OS and Opera -->
<meta name="theme-color" content="#4285f4">
<!-- Windows Phone -->
<meta name="msapplication-navbutton-color" content="#4285f4">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-status-bar-style" content="#4285f4">


Monday, 10 April 2017

BOOTSTRAP GALLERY CODE

HTML CODE  HERE 


<div class="row">

    <div class="col-lg-12">
        <h1 class="page-header">Thumbnail Gallery</h1>
    
            <div class="col-lg-3 col-md-4 col-xs-6 thumb">
            <a class="thumbnail" href="#" data-image-id="" data-toggle="modal" data-title="This is my title" data-caption="Some lovely red flowers" data-image="http://onelive.us/wp-content/uploads/2014/08/flower-delivery-online.jpg" data-target="#image-gallery">
                <img class="img-responsive" src="http://onelive.us/wp-content/uploads/2014/08/flower-delivery-online.jpg" alt="Short alt text">
            </a>
        </div>
            <div class="col-lg-3 col-md-4 col-xs-6 thumb">
            <a class="thumbnail" href="#" data-image-id="" data-toggle="modal" data-title="The car i dream about" data-caption="If you sponsor me, I can drive this car" data-image="http://www.picturesnew.com/media/images/car-image.jpg" data-target="#image-gallery">
                <img class="img-responsive" src="http://www.picturesnew.com/media/images/car-image.jpg" alt="A alt text">
            </a>
        </div>
            <div class="col-lg-3 col-md-4 col-xs-6 thumb">
            <a class="thumbnail" href="#" data-image-id="" data-toggle="modal" data-title="Im so nice" data-caption="And if there is money left, my girlfriend will receive this car" data-image="http://upload.wikimedia.org/wikipedia/commons/7/78/1997_Fiat_Panda.JPG" data-target="#image-gallery">
                <img class="img-responsive" src="http://upload.wikimedia.org/wikipedia/commons/7/78/1997_Fiat_Panda.JPG" alt="Another alt text">
            </a>
        </div>
</div>


<div class="modal fade" id="image-gallery" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="image-gallery-title"></h4>
            </div>
            <div class="modal-body">
                <img id="image-gallery-image" class="img-responsive" src="">
            </div>
            <div class="modal-footer">

                <div class="col-md-2">
                    <button type="button" class="btn btn-primary" id="show-previous-image">Previous</button>
                </div>

                <div class="col-md-8 text-justify" id="image-gallery-caption">
                    This text will be overwritten by jQuery
                </div>

                <div class="col-md-2">
                    <button type="button" id="show-next-image" class="btn btn-default">Next</button>
                </div>
            </div>
        </div>
    </div>
</div>


JS CODE HERE 

$(document).ready(function(){

    loadGallery(true, 'a.thumbnail');

    //This function disables buttons when needed
    function disableButtons(counter_max, counter_current){
        $('#show-previous-image, #show-next-image').show();
        if(counter_max == counter_current){
            $('#show-next-image').hide();
        } else if (counter_current == 1){
            $('#show-previous-image').hide();
        }
    }


    function loadGallery(setIDs, setClickAttr){
        var current_image,
            selector,
            counter = 0;

        $('#show-next-image, #show-previous-image').click(function(){
            if($(this).attr('id') == 'show-previous-image'){
                current_image--;
            } else {
                current_image++;
            }

            selector = $('[data-image-id="' + current_image + '"]');
            updateGallery(selector);
        });

        function updateGallery(selector) {
            var $sel = selector;
            current_image = $sel.data('image-id');
            $('#image-gallery-caption').text($sel.data('caption'));
            $('#image-gallery-title').text($sel.data('title'));
            $('#image-gallery-image').attr('src', $sel.data('image'));
            disableButtons(counter, $sel.data('image-id'));
        }

        if(setIDs == true){
            $('[data-image-id]').each(function(){
                counter++;
                $(this).attr('data-image-id',counter);
            });
        }
        $(setClickAttr).on('click',function(){
            updateGallery($(this));
        });
    }

});

Sunday, 26 March 2017

how to make a search form with multiple search options in php

Suppose These are fields:-

$user_name = $_POST[‘user_name’]$city = $_POST[‘city’]

Take a variable:-

$sql = ‘SELECT * FROM USER_TABLE WHERE 1=1’;

(i)   Now if user fills something in user_name:-

If(!empty($user_name))Then :-$sql = $sql . ‘AND user_name = ’.$user_name;

(ii) Now if user fills something in city:-

If(!empty($city))Then :-$sql = $sql . ‘AND city = ’.$city;And then run this query :- mysql_query($sql) 

Thursday, 9 March 2017

Equal height js

equalheight = function (container) {

var currentTallest = 0,
currentRowStart = 0,
rowDivs = new Array(),
$el,
topPosition = 0;
$(container).each(function () {

$el = $(this);
$($el).height('auto')
topPostion = $el.position().top;

if (currentRowStart != topPostion) {
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
rowDivs.length = 0; // empty the array
currentRowStart = topPostion;
currentTallest = $el.height();
rowDivs.push($el);
} else {
rowDivs.push($el);
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
}
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) {
rowDivs[currentDiv].height(currentTallest);
}
});
}

.... add your  class .... 

$(window).load(function () {
equalheight('.equal .pray');
});
$(window).resize(function () {
equalheight('.equal .pray');
});

Saturday, 4 February 2017

Jquery events not working on ajax loaded content

It's because you are binding the event on document ready. You have to use a delegate in order for this to work. Like on. It's because .header isn't on the page on the page when it's loaded. So no event is attached.
Your code should look some along the lines of this:

$('body').on('click','.heading',function(){
     $(this).css('color','red');  
});   
It doesn't have to be body, but an element which isn't loaded after document ready, which is a parent of .heading.

Saturday, 14 January 2017

PHP CURL POST & GET Examples – Submit Form using PHP CURL

PHP CURL POST & GET Examples – Submit Form using PHP CURL


In PHP CURL POST tutorial, I have explained how to send HTTP GET / POST requests with PHP CURL library.

Below are the examples covered in this article.
1) Send HTTP GET Request with CURL
2) Send HTTP POST Requests with CURL
3) Send Random User-Agent in the Requests
4) Handle redirects (HTTP 301,302)
5) Handle Errors.


Why we need PHP CURL ?

 
To send HTTP GET requests, simply we can use file_get_contents() method.
file_get_contents('http://gauravyadav94.blogspot.in/');

But sending POST request and handling errors are not easy with file_get_contents().

Sending HTTP requests is very simple with PHP CURL.You need to follow the four steps to send request.

 
step 1). Initialize CURL session    


$ch = curl_init();


step 2). Provide options for the CURL session   


curl_setopt($ch,CURLOPT_URL,"http://gauravyadav94.blogspot.in/");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//curl_setopt($ch,CURLOPT_HEADER, true); //if you want headers


CURLOPT_URL -> URL to fetch
CURLOPT_HEADER -> to include the header/not
CURLOPT_RETURNTRANSFER -> if it is set to true, data is returned as string instead of outputting it.

For full list of options, check this PHP Documentation.

step 3). Execute the CURL session  
$output=curl_exec($ch);


step 4). Close the session  
curl_close($ch);

Note: You can check whether CURL enabled/not with the following code.    
if(is_callable('curl_init')){
   echo "Enabled";
}
else
{
   echo "Not enabled";
}


1.PHP CURL GET Example

You can use the below code to send GET request.
   
function httpGet($url)
{
    $ch = curl_init(); 

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//  curl_setopt($ch,CURLOPT_HEADER, false);

    $output=curl_exec($ch);

    curl_close($ch);
    return $output;
}

echo httpGet("
http://gauravyadav94.blogspot.in/");


2.PHP CURL POST Example

PHP CURL POST & GET Examples
You can use the below code to submit form using PHP CURL.
   
function httpPost($url,$params)
{
  $postData = '';
   //create name value pairs seperated by &
   foreach($params as $k => $v)
   {
      $postData .= $k . '='.$v.'&';
   }
   $postData = rtrim($postData, '&');

    $ch = curl_init(); 

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_POST, count($postData));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);   

    $output=curl_exec($ch);

    curl_close($ch);
    return $output;

}

How to use the function:
   
$params = array(
   "name" => "Ravishanker Kusuma",
   "age" => "32",
   "location" => "India"
);


echo httpPost("http://
http://gauravyadav94.blogspot.in/examples/php/curl-examples/post.php",$params);


3.Send Random User-Agent in the Requests

You can use the below function to get Random User-Agent.  
function getRandomUserAgent()
{
    $userAgents=array(
        "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
        "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
        "Opera/9.20 (Windows NT 6.0; U; en)",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 8.50",
        "Mozilla/4.0 (compatible; MSIE 6.0; MSIE 5.5; Windows NT 5.1) Opera 7.02 [en]",
        "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; fr; rv:1.7) Gecko/20040624 Firefox/0.9",
        "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/48 (like Gecko) Safari/48"      
    );
    $random = rand(0,count($userAgents)-1);

    return $userAgents[$random];
}

Using CURLOPT_USERAGENT, you can set User-Agent string.
1  
curl_setopt($ch,CURLOPT_USERAGENT,getRandomUserAgent());


4.Handle redirects (HTTP 301,302)

To handle URL redirects, set CURLOPT_FOLLOWLOCATION to TRUE.Maximum number of redirects can be controlled using CURLOPT_MAXREDIRS.

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_MAXREDIRS,2);//only 2 redirects


5.How to handle CURL errors

we can use curl_errno(),curl_error() methods, to get the last errors for the current session.
curl_error($ch) -> returns error as string
curl_errno($ch) -> returns error number
You can use the below code to handle errors.  
function httpGetWithErros($url)
{
    $ch = curl_init(); 

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

    $output=curl_exec($ch);

    if($output === false)
    {
        echo "Error Number:".curl_errno($ch)."<br>";
        echo "Error String:".curl_error($ch);
    }
    curl_close($ch);
    return $output;
}

For the full list of errors, refer CURL errors

 

Wednesday, 4 January 2017

How They Hack Your Website

SQL Injection

SQL Injection involves entering SQL code into web forms, eg. login fields, or into the browser address field, to access and manipulate the database behind the site, system or application.When you enter text in the Username and Password fields of a login screen, the data you input is typically inserted into an SQL command. This command checks the data you've entered against the relevant table in the database. If your input matches table/row data, you're granted access (in the case of a login screen). If not, you're knocked back out.


The Simple SQL Injection Hack

In its simplest form, this is how the SQL Injection works. It's impossible to explain this without reverting to code for just a moment. Don't worry, it will all be over soon.

Suppose we enter the following string in a Username field:

' OR 1=1

double-dash-txt.png
The authorization SQL query that is run by the server, the command which must be satisfied to allow access, will be something along the lines of:

SELECT * FROM users WHERE username = ?USRTEXT '
AND password = ?PASSTEXT?

...where USRTEXT and PASSTEXT are what the user enters in the login fields of the web form.

So entering `OR 1=1 -- as your username, could result in the following actually being run:

SELECT * FROM users WHERE username = ?' OR 1=1 -- 'AND password = '?

Two things you need to know about this:
['] closes the [username] text field.

'

double-dash-txt.png
' is the SQL convention for Commenting code, and everything after Comment is ignored. So the actual routine now becomes:
SELECT * FROM users WHERE username = '' OR 1=1

1 is always equal to 1, last time I checked. So the authorization routine is now validated, and we are ushered in the front door to wreck havoc.

Tuesday, 3 January 2017

How do I get a YouTube video thumbnail from the YouTube API?

Each YouTube video has 4 generated images. They are predictably formatted as follows:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a url similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg
There is also a medium quality version of the thumbnail, using a url similar to the HQ:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg
For the standard definition version of the thumbnail, use a url similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/sddefault.jpg
For the maximum resolution version of the thumbnail use a url similar to this:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg
All of the above urls are available over http too. Additionally, the slightly shorter hostname i3.ytimg.com works in place of img.youtube.com in the example urls above.