Wednesday, 4 November 2015

How to send jQuery POST request on cross-domain

For the specific domain see below:
 
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
   header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); 
   header('Access-Control-Allow-Credentials: true');
   header('Access-Control-Max-Age: 86400');    // cache for 1 day
}
 
 
If you want to allow from any domain see below:

Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Headers "content-type"
 
 
Cheers!!! 

Monday, 23 September 2013

How to configure phpMyAdmin to access multiple servers from phpmyadmin?

Hi Guys,

Open the following URL in editor:

vim /etc/phpmyadmin/config.inc.php

Now,

   $i++;

    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    /* Server parameters */
    //if (empty($dbserver))
    $dbserver = 'servername';
    $cfg['Servers'][$i]['host'] = $dbserver;

    if (!empty($dbport)) {
        $cfg['Servers'][$i]['connect_type'] = 'tcp';
        $cfg['Servers'][$i]['port'] = $dbport;
    }
    //$cfg['Servers'][$i]['compress'] = false;
    /* Select mysqli if your server has it */
    $cfg['Servers'][$i]['extension'] = 'mysqli';
   
Cheers!!!

Monday, 16 September 2013

How to count files and line recursively using ubuntu?

Hellos,


How to count number of files recursively?

find . -type f | wc -l


How to count number of lines in files recursively?

wc -l `find  -name '*.php' -o -name '*.html' -o -name '*.xls' -type f`;

Cheers!!!









Thursday, 5 September 2013

How to Remove Save Draft & Preview Buttions.. and also Status: Draft & Visibility: Public in wordpress?

 Hello All,
 Please add below lines in your function.php file 
 
<?php
  add_action('admin_print_styles', 'remove_this_stuff');
  function remove_this_stuff() { ?>
    <style>
       #misc-publishing-actions, #minor-publishing-actions {display:none; }
    </style>
<?php } ?>
 
Cheers!!! 

Friday, 30 August 2013

How to remove admin bar from non admin users in wordpress?

Hi All,

Please add following script into your functions.php file:

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
      show_admin_bar(false);
    }
}

Cheers!

How to add login/logout button in wordpress menu?

Hi All,

Add following script into your functions.php

add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {

        ob_start();
        wp_loginout('index.php');
        $loginoutlink = ob_get_contents();
        ob_end_clean();

        $items .= '<li>'. $loginoutlink .'</li>';

    return $items;
}

Cheers!!!

Thursday, 8 August 2013

How to create cron job in YII framework?

Hi All,

Create cron.php file under project folder and write following:

<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/console.php';

require_once($yii);
Yii::createConsoleApplication($config)->run();

?>


Create console.php file under protected/config folder and write same data as written in main.php. see below:

/ This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'My Console Application',

    // preloading 'log' component
    'preload'=>array('log'),
        'import'=>array(
                'application.components.*',
                'application.models.*',
        ),

    // application components
    'components'=>array(
           
        // uncomment the following to use a MySQL database       
        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=bollywood_news',
            'emulatePrepare' => true,
            'username' => $dbUsername,
            'password' => $dbPassword,
            'charset' => 'utf8',
                        'enableProfiling' => true,
        ),
       
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                                        'logFile'=>'cron.log',
                    'levels'=>'error, warning',
                ),
                                array(
                                        'class'=>'CFileLogRoute',
                                        'logFile'=>'cron_trace.log',
                                        'levels'=>'trace',
                                ),
            ),
                       
        ),
    ),
   
);

Now,

Create CronjobCommand.php file under protected/commands folder. Here cronjob is a command.

<?php

class CronjobCommand extends CConsoleCommand {

    public function run($args) {
        // your code will come here...
    }

}

Now,

You have two ways to run your command:

Go to your project folder and write following:

a. php cron.php cronjob
b. php protected/yiic cronjob


Cheers!!!





?>