Saturday, 24 December 2016

Find location of php.ini using Terminal

To get Location of php.ini file using terminal






Run the following command in terminal


php --ini


if php is install this command will run

else you have to run first this one

sudo apt-get install php5-cli

then run

php --ini

it will give result as

Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File:         /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed:      /etc/php5/cli/conf.d/pdo.ini




Set Checkbox checked or unchecked using jQuery

Set Checkbox checked or unchecked using jQuery

                or
               
How to check checkbox is checked or unchecked using jQuery




Case 1    :    Single Checkbox using Id attribute


Html    :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
   
    <p id="check">Click me<p>

    <input type ="checkbox" name="chk_1" checked id="chk_1" value="1" /><label for="chk_1">Checkbox 1</label>
   
</body>
</html>

Script    :

    $('#check').on('click',function(){
        $("#chk_1").prop('checked', false); // Unchecks it
    })


--------------------------------------------------------------   X ---------------------------------------------------------------


Case 2    :    Multiple Checkboxes Using Class attribute

 Html    :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>

    <p id="check">Click me<p>

    <input type ="checkbox" name="chk_1" checked id="chk_1" value="1" class="mychechkbox"/><label for="chk_1">Checkbox 1</label>
    <input type ="checkbox" name="chk_2" checked id="chk_2" value="1" class="mychechkbox"/><label for="chk_2">Checkbox 2</label>
    <input type ="checkbox" name="chk_3" checked id="chk_3" value="1" class="mychechkbox"/><label for="chk_3">Checkbox 3</label>
    <input type ="checkbox" name="chk_4" checked id="chk_4" value="1" class="mychechkbox"/><label for="chk_4">Checkbox 4</label>

</body>
</html>


Script    :

    $('#check').on('click',function(){
        $(".mychechkbox").prop('checked', false); // Unchecks it
    })


--------------------------------------------------------------   X ---------------------------------------------------------------


Case 3    :    Single Checkbox Using name attribute

 Html    :

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
      <meta charset="utf-8">
      <title>JS Bin</title>
    </head>
    <body>

    <p id="check">Click me<p>

    <input type ="checkbox" name="chk_1" checked id="chk_1" value="1" /><label for="chk_1">Checkbox 1</label>
     
    </body>
    </html>

Script    :


    $('#check').on('click',function(){
        $("input[name='chk_1']:checkbox").prop('checked', false); // Unchecks it
    })
   
   

How to Reload Page on Anchor or label click ??

How to Reload Page on click??



Html Code:

<div id="test">
    <p>this is test.</p>
    <p id="closeAuction">Reload Page<p>
</div>




Jquery Code:

 $(document).ready(function() {
         $('#closeAuction').click(function() {
        location.reload();    
     });   
   });  




For Live Demo Click Here Live Demo

How to write a Simple jquery Code


How to write a Simple  jquery Code ??



Html code:


<input type="text" id="testid"  class="testclass" name="testname" placeholder="Event call using id on textbox click" >

<input type="text" id="testid2"  class="testclass2" name="testname2" placeholder="Event call using class on textbox leave" >


first thing download the latest jquery library from

http://code.jquery.com/jquery-migrate-1.2.1.min.js

then save it with "jquery-migrate-1.2.1.min.js" in your js folder or your project location


Jquery Code:

$(document).ready(function(){    // jquery start
    $("#testid").click(function(){    // text box click event
        alert("You have clicked");    // message to be displayed
    })
 });

This is the basic format for jquery beginner. you can use class instead of textbox id


$(document).ready(function(){    // jquery start
    $(".testclass2").blur(function(){    // text box blur event
        alert("This is use of class selector");    // message to be displayed
    })
 });


$(document).ready(function(){    // jquery start

    $("input").blur(function(){    // text box blur event on particular textbox
       
    $(this).css("border", "1px solid red");
       
    });
 });

Live Demo

How to add selected or active class to menu ??

If you want to add class selected or active to your menu just add the script in your project


Add jquery library using following url

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


Html:

<ul id="main-ul">
   <li><a href="#">About MHG</a></li>
    <li><a href="#">Workout Programs</a></li>
    <li><a href="#">Fitness Tips</a></li>
    <li><a href="#">Contact Us</a></li>        
    <li><a href="#">Read Our Blog</a></li>
</ul


CSS:

li{list-style:none;}
.selected{background:red;}
.selected a{color:#fff;}


Script:

$(document).ready(function(){
    $("#main-ul li").click(function(){
        $('li').removeClass("selected");
        $(this).addClass("selected");
    })
})


For live demo click Here

Get Image Name from url using jquery


First add the jquery file by including following following line

Jquery library:

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



Html:

    <img width="75px" height="75px" border="0" alt="Top Tech" src="http://unitedassemblers.com/Artwork/Blank.jpg">



Jquery:

$(document).ready(function(){
    var name = $('img').attr('src');
    var fileNameIndex = name.lastIndexOf("/") + 1;
    var filename = name.substr(fileNameIndex);
    if(filename='Blank.jpg')
    {
     alert('image name is '+filename);
    }
})


Live Demo :

Click here for live demo

Check div or any tag has html or not

Check div or any tag has html or not


<div id="box3">
   
</div>

$(document).ready(function(){
   if ($("#box3").text().length > 0) {
        console.log('not empty');
   }
   else{
        console.log('empty');
   }                
 });

Wednesday, 7 December 2016

Smooth scroll using jquery

Smooth scroll using jquery


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

<div class="">
    <a href="#commment" class="paythis">Go To comments</a>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <div id="commment" style="height:300px;width:300px;background:#d7d7d7; text-align:center;">
    <h3>Comment Section</h3>
</div>



<script>
   $('a.paythis').on('click',function(event){
        event.preventDefault();
        var hash = this.hash;
         $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 5000, function(){
  
        // Add hash (#) to URL when done scrolling (default click behavior)
        window.location.hash = hash;
      });
    })
</script>

Tuesday, 6 December 2016

IPTUX to run in background by mistake.


IPTUX to run in background by mistake.



Steps to resolve this

#1 show hidden files
#2 open %gconf.xml file located on

home/xxxx/.gconf/apps/iptux/%gconf.xml

Now find for "hide_startup" and change

name="hide_startup" mtime="xxxxxxxxxx" type="bool" value="true"

to

name="hide_startup" mtime="xxxxxxxxxx" type="bool" value="false"

Saturday, 19 November 2016

How to remove extra space from starting and ending of a string


How to remove extra space from starting and ending of a string




Simple write the following script:

jQuery('#your-form-id input[type=text]').one('keyup', function(){
        jQuery(this).val(jQuery.trim(jQuery(this).val()));
});

Friday, 17 June 2016

Wrap all into one div

How to wrap all into one div





Html


<div class='main'>
    <div class="a">a<div>
    <div class="b">b<div>
    <div class="c">c<div>
    <div id="d">d<div>
    <div class="e">e<div>
    <div id="f">f<div>
</div>



JQuery:

jQuery('.a, #d, .b, .c').wrapAll(jQuery('<div>').addClass('wrapbharat') );


Output after running jQuery will

<div class="main">
    <div class="wrapbharat"><div class="a">a<div>
    </div></div><div class="b">b<div>
    </div></div><div class="c">c<div>
    </div></div><div id="d">d<div>
    <div class="e">e<div>
    <div id="f">f<div>
</div>

Get Ip Address of website

How can I get the Ip Address of a website





Here are the providers link that give the Ip from website domain




IP & Domain Checker

Site 24x7

Check ip for any site on the web

Hcidata

You can also find by Terminal in Ubuntu & by Command Prompt in Windows systems by typing following commands

ping www.google.com

then it will show bytes from website ip




Monday, 13 June 2016

How to add class external to anchor that has href to other sites

Add class external to anchor that has href to other sites and target _blank to open them to new tab



jQuery

jQuery('a').filter(function() {
   return this.hostname && this.hostname !== location.hostname;
}).addClass("external");
jQuery('.external').attr('target','_blank');

Confirm before delete


Confirm before delete








Html:

<a href="delete.php"  onclick="return doconfirm()">Delete</a>

Javascript Function:


function doconfirm()
{
    contact=confirm("Are you sure you want to delete this?");
    if(contact!=true)
    {
        return false;
    }
}

Add class depending href of anchor

Add class depending href of anchor from current url



This jquery will add class active to anchor tag having that href

ex. url is www.test.com#tag

var hash = jQuery(this).attr('href').split("#");  //  it will give tag as result

jQuery(('a[href$="#'+hash[1]+'"]')).parent().addClass('active');

// this will add class to that a which have #tag as its href

Note: you can use these also


= is exactly equal
!= is not equal
^= is starts with
$= is ends with
*= is contains
~= is contains word
|= is starts with prefix (i.e., |= "prefix" matches "prefix-...")


Enable htaccess if not enabled on your server

"Page Not Found" Errors on every page except homepage.

Site is hosted on digital ocean or have file structure as var/www/html/yoursite





Enabling mod_rewrite by typing following command

    sudo a2enmod rewrite

Than restart apache server by following command

    sudo service apache2 restart

Now open file /etc/apache2/sites-enabled/000-default.conf

or by typing command given below

   sudo nano /etc/apache2/sites-enabled/000-default.conf
  
Inside that file, you will find the <VirtualHost *:80>

<Directory /var/www/html>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
</Directory>


after adding this your code should look like(indent shoud be proper)

<VirtualHost *:80>
    <Directory /var/www/html>

        . . .

    </Directory>

    . . .
</VirtualHost>

Now again restart server by typing command

   sudo service apache2 restart
  
Now add your htaccess and see that will work


Digital Ocean

Monday, 6 June 2016

How to create Login Logout functionality with session ?

How to create Login Logout functionality with session ?



In Few Basic Steps we can create Login-Logout with session

Step 1 :   
   
    Load Libraries in autoload.php        //Location :    application/config/autoload.php
   
    $autoload['libraries'] = array('database', 'email', 'session');
   

Step 2 :   
   
    Load Drivers in autoload.php        //Location :    application/config/autoload.php
   
    $autoload['drivers'] = array('session');
   
   
Step 3 :   
   
    Load Helper Libraries in autoload.php        //Location :    application/config/autoload.php
   
    $autoload['helper'] = array('url', 'file');


Now Comes Logical part We will create Two Controller files & Two View Files One for Before Login & Another for After Login Functionalities

Our Two controller will "Account" and "User" and views will "login_view" and "dashboard_view"

Step 4 :   

    First Create view using simple form on login_view page
   
    Form Code:
   
    <form method="post" action="<?php echo site_url('account/login');?>">
        <table>
            <tr>
                <td><input type="text" name="email" value="" placeholder="E-mail"/></td>
            </tr>
            <tr>
                <td><input type="password" name="password" value="" placeholder="*****" /></td>
            </tr>
            <tr>
                <td><input type="submit" name="login" value="Login" /></td>
            </tr>
        </table>
    </form>


Step 5 :   
   
    Add login logic on Account Controller Page We will use simple & static you can use dynamic using database
   
    function login()
    {
        $email=$this->input->post('email');
        $password=$this->input->post('password');
        if($email=='test@gmail.com' && $password=='123456')
        {
            $session_data=array(
                                'id'=>1,
                                'email'=>$email,
                                'islogin'=>True,
                            );
            $this->session->set_data($session_data);
            redirect('user');
        }
    }
   
Step 6:

    On User Controller create the constructor function so that it will called before calling any function
   
    public function __contruct()
    {
        parent::__contruct();
        if((!$this->session->has_userdata('id'))||(!$this->session->has_userdata('email'))||(!$this->session->has_userdata('islogin')))
        {
            redirect('account/login');
        }
    }

Step 7:

    Create a function on User controller to show welcome page simply load welcome page
   
    function dashboard()
    {
        $this->load->view('dashboard');
    }
   
Step 8:
   
    Create dashboard view to show welcome message and user email id
   
    <a href="<?php echo site_url('account/logout');?>">Logout</a>
   
    <h3>Hello <?php echo $this->session->userdata('email');?><h3>
   
Step 9:

    Create Logout functionality on Account controller page
   
    function logout()
    {
        $this->session->sess_destroy();
        redirect('account/login');
    }

Change Upload limit using htaccess in drupal


Change Upload limit using htaccess in drupal


find for mod_php5.c

and add these two lines

php_value upload_max_filesize 30M
php_value post_max_size 30M

if not found then add this code in your htaccess file



<IfModule mod_php5.c>
    php_value upload_max_filesize 30M
    php_value post_max_size 30M
</IfModule>

Remove all p tag contains space


How to remove all p tag contains space


Solution : 

jQuery('p').each(function(){
   var htm=jQuery(this).html();
  if(htm=='&nbsp;')
  {
    jQuery(this).remove();
  }
})

This small jquery will remove all empty p tag on page

To sort item alphabetically

To sort item alphabetically using jquery





Html:



        <ul id="list">
            <li id="34">Peter</li>
            <li id="92">Mary</li>
            <li id="49">Paul</li>
            <li id="12">Allen</li>
            <li id="24">James</li>
            <li id="83">Vicki</li>
            <li id="68">Brock</li>
            <li id="1200">Dana</li>
            <li id="56">Frank</li>
            <li id="128">Gil</li>
            <li id="146">Helen</li>
        </ul>
      
jQuery:


var mylist = jQuery('list');
var listitems = mylist.children('li').get();

listitems.sort(function(a, b)
{
   return jQuery(a).text().toUpperCase().localeCompare(jQuery(b).text().toUpperCase());
})

mylist.empty().append(listitems);

//$.each(listitems, function(idx, itm) { mylist.append(itm); });


Remove all empty tags in class

How to remove all empty tags in class






Solution:


jQuery(function() {
  jQuery(".region-content p:empty").remove();
});

I will remove all empty tag inside "region-content" class





Add css depending on device

How to add css depending on device like ipad, android, desktop etc  ?



Solution:


jQuery(document).ready(function(){
   
    var deviceAgent = navigator.userAgent.toLowerCase();
    alert(deviceAgent);
   
     if(deviceAgent.match(/android/i))
     {
            alert('android');
     }
       
     if(deviceAgent.match(/ipad/i))
     {
           jQuery('head').append("<link rel='stylesheet' href='android.css' type='text/css' />");
     }
       
  console.log(navigator.userAgent.toLowerCase());

})

Create page tpl for taxonomy vocabulary

How to create page tpl for taxonomy vocabulary



Solution:

find for themename_preprocess_page add this is template.php

if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)))
{
    $tid = arg(2);
   
    $vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
   
    $vars['theme_hook_suggestions'][] = 'page__vocabulary__'.$vid;
}

now create tpl named as "page--vocabulary--X.tpl.php";

Lock may available Drupal

How to remove error lock may available in drupal

Drupal showing me an error
includes/database/database.inc on line 2171





open php.ini and my.cnf located on /opt/lampp/etc
find max and change all limits to 1024 and max_execution_time=0

Get field value in Form alter drupal 8

Get field value in Form alter drupal 8



syntax:    $form_state->getValue('machine name');


to get machine name print $form_state->getValue();    // it will show all value of form

$field_e_mail_address=$form_state->getValue('field_e_mail_address');
$emailId=$field_e_mail_address[0]['value'];


Print nid in drupal 8 twig file or template file

print nid in drupal 8 twig file or template file




add this code in  _preprocess_page in .theme file at following location

ryder/themes/theamname/theamname.theme

find for _preprocess_page and add this

    $node = \Drupal::routeMatch()->getParameter('node');
    if ($node) {
      $variables['nodeid'] = $node->id();
    }

now in twig print as {{ nodeid }}

Remove welcome message in drupal from front page

How to remove welcome message in drupal from front page?



To Remove "Welcome Message & no frontpage content created yet" in drupal

open the teamplate file of the current default theme

and search for "_preprocess_page";
 now add code just before the closing of the function

 Code:


  if (drupal_is_front_page()) {
    unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is created"
    drupal_set_title(''); //removes welcome message (page title)
  }
 


For example:
 
function MYTHEME_preprocess_page(&$vars) {
  if (drupal_is_front_page()) {
    unset($vars['page']['content']['system_main']['default_message']); //will remove message "no front page content is created"
    drupal_set_title(''); //removes welcome message (page title)
  }
}

Sunday, 5 June 2016

Remove index.php from codeigniter url placed in subdomain



<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /mop/index.php/$1 [L,QSA]
</IfModule>


Here mop is folder name placed in public_html
public_html/mop/index.php


Note: Replace mop with your folder name

Remove index.php from url codeigniter

How to remove index.php from url codeigniter


Goto        :    application->config->config.php

Find         :    $config['index_page'] = 'index.php';

Replace        :    $config['index_page'] = '';

Now create new htaccess file & paste following code and save by name as .htaccess on root directory of your project


<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>


Now Refresh the url index.php is removed from url