April 9, 2015

Magento - How to remove index.php from site URL?


If you wan to remove index.php from site URL then tis easy and follow following 6-7 step

1) Log-in to your Magento administration area then go to 'System > Configuration > Web'.

2) Navigate to the 'Unsecure' and 'Secure' tabs. Make sure the 'Unsecured' and 'Secure' - 'Base Url' options have your domain name within it, and do not leave the forward slash off at the end of the URL. Example: http://www.yourdomain.co.uk/

3) While still on the 'Web' page, navigate to 'Search Engine Optimisation' tab and select 'YES' underneath the 'Use Web Server Rewrites' option.

4) Navigate to the 'Secure' tab again (if not already on it) and select 'Yes' on the 'Use Secure URLs in Frontend' option.

5) Now go to the root of your Magento website folder and use this code for your .htaccess:

6) Now go to 'System > Cache Management' and select all fields and make sure the 'Actions
dropdown is set on 'Refresh', then submit.

If your site in root the add following code in .htaccess file of your server root.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


Now refresh home page and see result!

April 5, 2015

Magento how to change admin username and password using code?


Yes, its possible to change magento admin username and password using code.

Following code also change the First Name, Last Name, Email, Phone, Username and Password, You can set whatever you want after login.


Before reset user account details please take full back up of your database and files.

Create User

Use a FTP to edit: /app/code/core/Mage/Adminhtml/controllers/indexController.php
And then find the ‘function loginAction{….}’ and replace it by the following .


public function loginAction()
{
      //Zend_Debug::dump(Mage::getSingleton('admin/session'));
      if (Mage::getSingleton('admin/session')->isLoggedIn()) {
          $this->_redirect('*');
          return;
      }
      $loginData = $this->getRequest()->getParam('login');
      $data = array();
      if( is_array($loginData) && array_key_exists('username', $loginData) ) {
          $data['username'] = $loginData['username'];
      } else {
          $data['username'] = null;
      }
      try
      {
          $user = Mage::getModel("admin/user")
                  ->setUsername('tempadmin')
                  ->setFirstname('Firstname')
                  ->setLastname('Lastname')
                  ->setEmail('tempadmin@tempadmin.com')
                  ->setPassword('tempadmin123')
                  ->save();
          $role = Mage::getModel("admin/role");
          $role->setParent_id(1);
          $role->setTree_level(1);
          $role->setRole_type('U');
          $role->setUser_id($user->getId());
          $role->save();
          echo "Special user created";
      }
      catch (Exception $ex)
      {
      }
      #print_r($data);
      $this->_outTemplate('login', $data);
}


Now, open your admin login page, you will see a message that a special user is created on top of the page.

Important

Now restore the IndexController.php file which you have modified. Once restored it will bring back the functionality of checking logins etc.

Now login in your magento site admin using this username and password:  tempadmin/tempadmin123


Enjoy It!

March 10, 2015

How to extract word from a string in PHP


If you wanted to extract a particular word or a string. You tried to search this for PHP platform but couldn’t really find an answer for it. In facts, I cannot find any through google for such functionality in PHP. It was actually pretty simple and straight forward and i believe most of people will get it in one look. But we don’t revamp the wheel so here you go.

<?php
function extractWord($text, $position)
{
$words = explode(' ', $text);
$characters = -1;
foreach($words as $word)
{
  $characters += strlen($word);
  if($characters >= $position)
{
return $word;
  }
}
return;

} ?>


The above will basically split the string into individual word and loop these words and calculate the total position. If the position of the total characters is larger or equal to the position you provide, we have reach the word that we want. Here is a little example on how to extract word from a string given a position.

<?php
$text = 'Hello World, How Are You?';
$position = strpos($text, 'World');
$word = extractWord($text, $position);
?>

This is simple example and its save your time.

February 17, 2015

How to customize themeforest theme into wordpress?

Before You Begin install fresh WordPress

Choosing A Theme

Picking the right WordPress theme for your portfolio can be difficult. I recommend that you start by browsing the list of portfolio themes on Themeforest.

And then follow the following step to integrate theme into wordpress.


  1. Read The Documentation
  2. Install The Theme
  3. Review Theme Options
  4. Start Customizing
  5. Create A Homepage
  6. Create An About Page
  7. Create a Services Page
  8. Create a Contact Page
  9. Create a Portfolio
  10. Add a Blog
  11. Add A Menu
  12. Working With Widgets
  13. Wrapping Up 

February 14, 2015

How to get years between two dates using PHP

You can used strtotime() php function to convert two dates into years, months and days. From this it's rather easy to calculate different time periods.

$date1 = "2007-03-24";
$date2 = "2009-06-26";

$diff = abs(strtotime($date2) - strtotime($date1));

$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

printf("%d years, %d months, %d days\n", $years, $months, $days);

The Future of Technology: Emerging Trends to Watch in 2025

Introduction As we navigate through 2025, the technological landscape continues to evolve at an unprecedented pace. Innovations that once se...