How to create category from csv file

How to create bulk parent and sub category from csv file
Instruction:- Copy and save this code file in root folder of Magento and run it. exp :- http://yoursite/cat.php
<?php
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app('admin'); 
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
ini_set('max_execution_time', 1800);
umask(0);
/************ Get CSV file **************/
  $path = Mage::getBaseDir('media') . DS . 'catcsvfile'; //file path of csv
  $files = glob($path.'/*'); // get all file names
  if($files){
   foreach($files as $file){ // iterate files   
     $csv  =  new Varien_File_Csv();
     $data =  $csv->getData($file); //path to csv
        }  
 array_shift($data);
 foreach($data as $_data){
/*****************  Prent category creation *****************/
   /*****************  Prent category creation *****************/
   $Pcat =  utf8_encode($_data[0]); // column to create parent category
   $getcategory = Mage::getResourceModel('catalog/category_collection')->addFieldToFilter('name',$Pcat);
   $catData = $getcategory->getData();
   $catcount  = count($catData);
    if($catcount==0 && !empty($Pcat))
   {  $category = Mage::getModel('catalog/category');
     $category->setName($Pcat);
     $category->setUrlKey($Pcat);
     $category->setMetaTitle($Pcat);
     $category->setIsActive(1);
     $category->setDisplayMode('PRODUCTS');
     $category->setIsAnchor(1); //for active achor
     $category->setStoreId(Mage::app()->getStore()->getId());
     $parentCategory = Mage::getModel('catalog/category')->load(2);
     $category->setPath($parentCategory->getPath());
     $category->save();
  }
/*    Child category creation             **********************/
   global $childcat;
    $childcat = utf8_encode($_data[1]); // column to create sub category
   $pgetcategory = Mage::getResourceModel('catalog/category_collection')->addFieldToFilter('name',$childcat);
   $pcatData = $pgetcategory->getData();
   if(!$pcatData) {
    $getcategory2 = Mage::getResourceModel('catalog/category_collection')->addFieldToFilter('name',$Pcat);
    $catData2 = array();
   $catData2 = $getcategory2->getData();
   if(!empty($catData2)){
   $ParentCategoryId2 = $catData2[0]['entity_id'];   
     $category = Mage::getModel('catalog/category');
     $category->setName($childcat);
     $category->setUrlKey($childcat);
     $category->setMetaTitle($childcat);
     $category->setIsActive(1);
     $category->setDisplayMode('PRODUCTS');
     $category->setIsAnchor(1); //for active achor
     $category->setStoreId(Mage::app()->getStore()->getId());
     $parentCategory = Mage::getModel('catalog/category')->load($ParentCategoryId2);
     $category->setPath($parentCategory->getPath());
     $category->save();
   }  
   }
 }
}
else
{
echo 'file not found';
}
?>

How to get category id by category name in magento

<?php
$category = Mage::getResourceModel('catalog/category_collection')->addFieldToFilter('name','cateNameHere'));
    $catData = $category->getData();      
 $categoryId = $catData[0][entity_id];
 echo $categoryId;
 ?>

How to delete all category in magento

Instruction :- Copy and save this code file in root folder of Magento and run it; exp :- http://yoursite/deletecat.php
<?php 
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
ini_set('max_execution_time', 1800);
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
foreach(Mage::getModel('catalog/category')
->getCollection()
->addFieldToFilter('entity_id', array('gt' => 2)) as $cat) {
$cat->delete();
}
?>

How to write secure code in Php -1

PHP is a very easy language to learn, and many people without any sort of background in programming learn it as a way to add interactivity to their web sites. Unfortunately, that often means PHP programmers, especially those newer to web development, are unaware of the potential security risks their web applications can contain. Here are a few of the more common security problems and how to avoid them.

Rule Number One: Never, Ever, Trust Your Users
It can never be said enough times, you should never, ever, ever trust your users to send you the data you expect. I have heard many people respond to that with something like "Oh, nobody malicious would be interested in my site". Leaving aside that that could not be more wrong, it is not always a malicious user who can exploit a security hole - problems can just as easily arise because of a user unintentionally doing something wrong.

How to write secure code in Php -2

Learn how to improve your security a little further with the second part of this PHP tutorial.
In Writing Secure PHP, I covered a few of the most common security holes in websites. It's time to move on, though, to a few more advanced techniques for securing a website. As techniques for 'breaking into' a site or crashing a site become more advanced, so must the methods used to stop those attacks.


File Systems
Most hosting environments are very similar, and rather predictable. Many web developers are also very predictable. It doesn't take a genius to guess that a site's includes (and most dynamic sites use an includes directory for common files) is an www.website.com/includes/. If the site owner has allowed directory listing on the server, anyone can navigate to that folder and browse files.