Add product into cart in magento1

Add simple product into cart into magento?

[php]
$product = Mage::getModel(‘catalog/product’)->load($pro_id);
$session = Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’));
$cart = Mage::helper(‘checkout/cart’)->getCart();
$cart->addProduct($product, $pro_quantity);
$session->setLastAddedProductId($product->getId());
$session->setCartWasUpdated(true);
$cart->save();
[/php]

Note:- (1) $pro_id is a product id
(2) $pro_quantity is a quantity of the product which will be add into cart.

Add configurable product into cart into magento?

[php]
$product = Mage::getModel(‘catalog/product’)->load($pro_id);
$params = array(‘product’ => $pro_id,’super_attribute’ => array($attribute_id=>$attribute_valid),’qty’ => $pro_quantity);
$session = Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’));
$cart = Mage::helper(‘checkout/cart’)->getCart();
$cart->addProduct($product, $params);
$session->setLastAddedProductId($product->getId());
$session->setCartWasUpdated(true);
$cart->save();
[/php]

Note:- (1) $pro_id is a product id
(2) $pro_quantity is a quantity of the product that will be added into the cart.
(3) $attribute_id is an attribute id.
(4) $attribute_valid is a value id of the attribute.