Add product into cart in magento

Add simple product into cart into magento?

$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();

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?

$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();

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