Monday, 8 July 2019

how to password protected in htaccess url in pacific country ?

.htaccess

File content:

AuthType Basic
AuthName "Restricted access"
AuthUserFile /home2/b4x4u4fu/public_html/.htpasswd
require valid-user
Order allow,deny
Allow from all
deny from 1.6.0.0/1

command line run : htpasswd -c .htpasswd [username]

how to password protected in php url in pacific country ?

/* ------------------------------ */

function ip_visitor_country()
{

    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];
    $country  = "Unknown";

    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.geoplugin.net/json.gp?ip=".$ip);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $ip_data_in = curl_exec($ch); // string
    curl_close($ch);

    $ip_data = json_decode($ip_data_in,true);
    $ip_data = str_replace('"', '"', $ip_data); // for PHP 5.2 see stackoverflow.com/questions/3110487/

    if($ip_data && $ip_data['geoplugin_countryName'] != null) {
        $country = $ip_data['geoplugin_countryName'];
    }

    return $country;
}

$ip =trim(ip_visitor_country());

if($ip=='India'){

    function CheckAccess()

{

  $result = (isset($_SERVER['PHP_AUTH_USER']) &&

            $_SERVER['PHP_AUTH_USER'] == 'admin' &&

            $_SERVER['PHP_AUTH_PW'] == 'admin@123');

  if (!$result)

  {

   header('WWW-Authenticate: Basic realm=“Test restricted area”');

   header('HTTP/1.0 401 Unauthorized');

   return false;

  }

  else

   return true;

}


if (!CheckAccess())

{

  //show the access denied message and exit script

  echo 'Access denied!';

  exit;

}

}

//exit;
/* ------------------------------------- */

Wednesday, 19 June 2019

How to Set up an SSH Server on a Home Computer

Step 1: sudo apt-get upgrade

Step 2: sudo apt-get install openssh-client

Step 3:  sudo apt-get install openssh-server


ssh targetusername@xxx.xxx.xx.xxx (target IP address for example 192.168.0.10)

Monday, 27 May 2019

Magento 2.X - Display Recently Viewed Products block on Product Detail page

catalog_product_view.xml
===================================
<referenceContainer name="content">
       
          <block class="Magento\Reports\Block\Product\Widget\Viewed" after="-" name="recently_viewed" cacheable="false" template="Magento_Reports::widget/viewed/content/viewed_grid.phtml">
            <action method="setPageSize">
              <argument name="page_size" xsi:type="number">5</argument>
            </action>
          </block>
         
        </referenceContainer>

How to Add Custom Field to Customer Address in magento 1.9

<?php
$installer = new Mage_Customer_Model_Entity_Setup('core_setup');

$installer->startSetup();

$installer->addAttribute('customer_address', 'flatnumber', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Door / Flat Number',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));
Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'flatnumber')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();
$installer->endSetup();

 ?>

Monday, 20 May 2019

How to send forgot password link programmatically in magento 1.9

How to send forgot password link programmatically in magento 1.9

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app('default');
$yourCustomerEmail="bliss.jaimin@gmail.com";
$customer = Mage::getModel('customer/customer')
    ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
    ->loadByEmail($yourCustomerEmail);
if ($customer->getId()) {
    try {
        $newResetPasswordLinkToken =  Mage::helper('customer')->generateResetPasswordLinkToken();
        $customer->changeResetPasswordLinkToken($newResetPasswordLinkToken);
        $customer->sendPasswordResetConfirmationEmail();
    } catch (Exception $exception) {
        Mage::log($exception);
    }
}

Monday, 25 March 2019

Programmatically assign customer to a quote in magento

$customer = Mage::getModel('customer/customer')->load($userId);

$quote = Mage::getModel('sales/quote')->load($quoteId);
$quote->setCustomer($customer);
$quote->save();