November 10, 2014

What happen when Browser Cookie will Removed, Session retains as its ?


When webpage was loaded, unique session id will generated and that stored in cookie. If cookie will removed then session cant retain.

PHP Session and Cookie


The main difference between sessions and cookies is that cookies are stored in the user's browsers, and session are stored in server.

A cookie is small file that store in user's computer. Cookie data expiry depend on expiration date where session retain until browser run.

PHP List of array sort functions

sort().

rsort().

natsort().

natcasesort().

ksort().

krsort(). 

asort().

arsort().


Use of array_map Function in Real Time ?

It will apply for many things. For example want to do php function for set of elements will use that
Example

If have like below

$first_name = trim($_POST['firstname']);


$lastname = trim($_POST['lastname']);

but instead of above

$_POST = array_map("trim", $_POST);


$array = array_map("trim", $array);


It will remove the spaces for the set of elements.



How to Add the Element to the array First & Last, how to remove the same ?


array_push - Adding elemen to the last

array_unshift - First element to prepend

array_pop - Remove the first element of the array

array_shift - Remove the last element

How to determine PHP version in Servers ?

PHPINFO gives various detail scripting running system, Apache built-in modules, PHP working directory, PHP modules, PERL information and third party system information that are used in server.

phpinfo();

Type of Magento Sessions

Core/Session:

Mage::getSingelton('core/session')

Handles information about end user ip address, messages, cookies

Customer/Session:

Mage::getSingleton('customer/session')

Handles information about the customer.

Checkout/Session:

Mage::getSingleton('checkout/session')

Handles information about the checkout, cart and details of guest account user 

October 28, 2014

Magento Interview Questions


Getting order id for new order


Magento get new order id based on "eav_entity_store" table

PHP Interview Questions


Echo vs print.


echo() and print() are language constructs in PHP, both are used to output strings.

echo() can take multiple expressions whereas print cannot take multiple expressions.

August 07, 2014

Magneto create admin user progrmatically

### Create New admin User programmatically. ####
require_once('./app/Mage.php');
umask(0);
Mage::app();

try {
 $user = Mage::getModel('admin/user')
           ->setData(array(
                'username' => '[user_name]',
                'firstname' => 'Admin',
                'lastname' => 'Admin',
                'email'  => '[user_email]',
                'password' => 'admin123',
                'is_active' => 1
               ))->save();

} catch (Exception $e) {
 echo $e->getMessage();
 exit;
}

//Assign Role Id
try {
       //Administrator role id is 1 ,Here you can assign other roles

     $user->setRoleIds(array(1))  
          ->setRoleUserId($user->getUserId())
          ->saveRelations();

} catch (Exception $e) {
    echo $e->getMessage();
    exit;
}

echo 'Admin user created successfully';