search
top

Coupon Codes Generator

I am describing here a way to generate coupon codes with custom configurable parameters. <?php function re($l,$d,$pre,$suf,$charset,$del) { $length = max(1,$l); $split = max(0,$d); $suffix = $suf; $prefix = $pre; $splitChar = $del; $code = ''; $charsetSize = count($charset); for ($i=0; $i<$length; $i++) { $char = $charset[mt_rand(0,...
read more

Random String Generator

Below is a simple script to generate random string/password using PHP. You can customize the same by adding special characters. <?php function randomPassword() { $alphabet = "abcdefghijklmnopqrstuwxyz ABCDEFGHIJKLMNOPQRSTUWXYZ 0123456789"; $pass = array(); //remember to declare $pass as an array $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache ...
read more

Custom Email Templates in Magento

Hello, I am explaining here the method for sending custom emails using the custom email templates with variables. 1) Create an email template from Admin-end > System > Transactional Emails, for example lets put this as Template Content <!--@vars { "htmlescape var=$customer.name":"Customer Name", "var customer.email":"Customer Email" } @--> Dear...
read more

Useful code in Magento

I am listing here the codes useful in Magento Magento Home URL - Mage::getBaseUrl(); Magento Home Directory - Mage::getBaseDir(); URL of a file in the skin directory - $this->getSkinUrl(‘images/myfile.png’); // in a template or Block - Mage::getDesign()->getSkinUrl(‘images/myfile.png’); // from anywhere Format a price value - Mage::helper(‘core’)->formatPrice($amount); Get...
read more

Passing by Reference

I am listing here a simple example to explain ‘passing by reference’ in PHP. I hope it is helpful. <?php $a = 5; echo 'A1->'.$a.'<br/>'; $b = 6; $a =& $b; echo 'A2->'.$a.'<br/>B1->'.$b.'<br/>'; global $var; function foo(&$var) { $var++; } $a=5; echo 'A3->'.$a.'<br/>'; foo($a); echo 'A4->'.$a.'<br/>Var->'.$var; ?> For...
read more

Reading XML

I am listing here method for reading XML file or XML string with the help of PHP. <?php $xml =<<<EOT <?xml version="1.0"?> <root> <section name="Section1"> <category id="Category1" name="google"> <article name="article1">value1</article> </category> <category id="Category2"...
read more

Get Product ID and Product Name in Magento

In Magento eCommerce while working with catalog model, There arise the need to fetch product details from product id. We can get all product details if we have product id. But sometimes we only have product name, so we need to get product id for getting product details. I am listing here both the method. 1) Product details from Product ID. <?php $model = Mage::getModel('catalog/product') //getting...
read more

Extracting String

This is small but very useful script. I have shown example for extracting only ‘src’ value from the ‘img’ tag, but you can modify and use as per your requirement using ‘preg_match_all’ function. <?php $src= '<img height="120" width="120" border="0" src="http://www.somesite.com/abc.jpg" class="image"/>'; preg_match_all('/(src)=("[^"]*")/i',$src,...
read more

Page Redirect

I have written a script for getting the files list from directory and redirecting the page on selecting option from the select box. So you will get the script for fetching all the files from current directory and redirecting page on selection. <h>Please select option</h> <?php $path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; //current directory physical path $dir_handle...
read more

Get IP Address in PHP

Many times we need the IP Address of the User visiting our website in our Application. I am listing here the method to get the User IP Address, hope it might be useful to many of you. //function for getting IP //start function getuserip() { if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) return $_SERVER["HTTP_X_FORWARDED_FOR"]; ...
read more

« Previous Entries

top