Tuesday, 7 February 2017

Send email from localhost in php (XAMPP, WAMP, LAMP)

We face trouble sending email from your localhost server XAMPP, WAMP, LAMP. Because When we setup apache in local system it won’t by default setup for SMTP server . So if we want to send email from your localhost you must have to setup SMTP configuration in php.ini file or we have to use external SMTP server. There are lot’s of external SMTP server are available like Gmail, Hotmail, Yahoo etc. They allow to send email by using their SMTP configuration, we only need to configure some parameter in your local configuration or in your phpmailer code.
First download latest phpmailer class form here https://github.com/PHPMailer/PHPMailer
After that include PHPMailerAutoload.php on your mailing page and configuring SMTP settings.

<?php
require 'PHPMailerAutoload.php'; 
$mailObj = new PHPMailer;  
$to = "hi@iamrohit.in"; 
$subject = "Test mail"; 
$msg = "This is simple test mail sending by phpmailer class"; 
$mailObj->AddAddress($to, 'Rohit');
$mailObj->SetFrom('from@example.com', 'Example');
$mailObj->AddReplyTo('reply-to@example.com', 'Reply-Example');
$mailObj->Subject = $subject;
$mailObj->AltBody = 'To view the message, please use an HTML compatible email viewer!'; 
$mailObj->MsgHTML($msg);
 
// SMTP Settings
$mailObj->isSMTP();              // Set mailer to use SMTP
$mailObj->Host = 'smtp1.example.com;smtp2.example.com';   
// Specify main and backup SMTP servers
$mailObj->SMTPAuth = true;             // Enable SMTP authentication
$mailObj->Username = 'user@gmail.com';  // SMTP username
$mailObj->Password = 'password';   // SMTP password
$mailObj->SMTPSecure = 'tls';    // Enable TLS encryption, `ssl` also accepted
$mailObj->Port = 587;
 
$mailObj->Send();
if(!$mailObj->Send()) {
echo "There was an error sending the e-mail";
} else {
echo "E-Mail has been sent successfully";
}
?>

Sunday, 5 February 2017

Change Entry Title of WooCommerce Endpoints in My Accounts Page

One way around changing the entry-title of the WooCommerce custom endpoint is to use the_title filter with the in_the_loop conditional.
Add below code to your active theme's function.php
/*
 * Change the entry title of the endpoints that appear in My Account Page - WooCommerce 2.6
 * Using the_title filter
 */
function wpb_woo_endpoint_title( $title, $id ) {
 if ( is_wc_endpoint_url( 'downloads' ) && in_the_loop() ) { // add your endpoint urls
 $title = "Download MP3s"; // change your entry-title
 }
 elseif ( is_wc_endpoint_url( 'orders' ) && in_the_loop() ) {
 $title = "My Orders";
 }
 elseif ( is_wc_endpoint_url( 'edit-account' ) && in_the_loop() ) {
 $title = "Change My Details";
 }
 return $title;
}
add_filter( 'the_title', 'wpb_woo_endpoint_title', 10, 2 );

For more details visit: https://wpbeaches.com/change-rename-woocommerce-endpoints-accounts-page/

Friday, 3 February 2017

Create multi dimentional unique array for specific code in php

Create multidimensional array unique for any single key index.
My array is like this,
<?php
$details 
= array(
    
=> array("id"=>"1""name"=>"Mike",    "num"=>"9876543210"),
    
=> array("id"=>"2""name"=>"Carissa""num"=>"08548596258"),
    
=> array("id"=>"1""name"=>"Mathew",  "num"=>"784581254"),
); 
?> 
You can make it unique for any field like id, name or num.
I have develop this function for same : 
<?php function unique_multidim_array($array$key) {
    
$temp_array = array();
    
$i 0;
    
$key_array = array();
   
    foreach(
$array as $val) {
        if (!
in_array($val[$key], $key_array)) {
            
$key_array[$i] = $val[$key];
            
$temp_array[$i] = $val;
        }
        
$i++;
    }
    return 
$temp_array;
?> Now, call this function anywhere from your code, 
something like this, 
<?php
$details 
unique_multidim_array($details,'id'); ?> Output will be like this : 
<?php
$details 
= array(
    
=> array("id"=>"1","name"=>"Mike","num"=>"9876543210"),
    
=> array("id"=>"2","name"=>"Carissa","num"=>"08548596258"),
); 
?>

For more information visit: http://php.net/manual/en/function.array-unique.php

Sunday, 29 January 2017

Remove Script and Stylesheet Version in Wordpress

Paste below code in the active themes function.php
add_filter( 'script_loader_src', 'remove_version' );
add_filter( 'style_loader_src', 'remove_version' );
function remove_version ( $src ) {
  global $wp_version;
  $version_str = '?ver='.$wp_version;
  $version_str_offset = strlen( $src ) - strlen( $version_str );
  if( substr( $src, $version_str_offset ) == $version_str )
    return substr( $src, 0, $version_str_offset );
  else
    return $src;
}

Wednesday, 25 January 2017

Downlaod file using CodeIgniter

CodeIgniter has a nice helper functions to download files. Its a nice way to download from server without any hassle just writing one single controller method.
public function download ($file_path = "") {
            // load ci download helder
            $this->load->helper('download');
            // get download file path and store it in $data array
            $data['download_file'] = $file_path;    
            // load view file    
            $this->load->view("download_view",$data);
            redirect(current_url(), "refresh");                      
        }
In view section(download_view.php), just call the download function thats it.
if( ! empty($download_file))
{
        //If you want to download an existing file from your server you'll need to read the file into a string
        $data = file_get_contents(base_url("/path/".$download_file)); // Read the file's contents
        $name = $download_file;
        force_download($name, $data);
}

Preventing SQL injection in Codeigniter

In codeIgniter ,we no need to use mysql_real_escape_string() function, Codeigniter provides inbuilt functions and libraries to generate SQL queries by using those methods or functions we can avoid SQL injections.
There are three methods to prevent SQL injections in Codeigniter application, they are
1) Escaping Queries
2) Query Binding
3) Active Record Class
1. Preventing SQL injection in Codeigniter using Escaping Query Method
Example:
   $email= $this->input->post('email');
   $query = 'SELECT * FROM subscribers_tbl WHERE user_name='.$this->db->escape($email);
   $this->db->query($query);
2. Preventing SQL injection in Codeigniter using Query Binding Method
Example:
    $sql = "SELECT * FROM subscribers_tbl WHERE status = ? AND email= ?";
    $this->db->query($sql, array('active', 'support@keredari.com));
3. Preventing SQL injection in Codeigniter using Active Record Class
$this->db->get_where('subscribers_tbl',array('status' => 'active','email' => 'support@keredari.com'));

Sunday, 22 January 2017

Remove paypal checkout on product page in Prestshop

Follow below steps to fix it:
1. Login into admin panel
2. Click to Position under Module and Serives tab
3. Scroll to displayFooterProduct and unhook it.
That's it.