HSBC - MIGS Payment Gateway Integration - PHP

When you receiving the set of document from the HSBC for the MIGS payment gateway you will feel OMG!!!

But after gone through them and had a very tough time to integrate this to one of the site. but finally when we look at that it looks like a very easy one.

So i thought to share it with all to make your life Easy.

here is the source :
________________________________________________________________
$testarr = array(
"vpc_Amount" => $finalprice*100,//Final price should be multifly by 100
"vpc_AccessCode" => "1234ABCD",//Put your access code here
"vpc_Command"=> "pay",
"vpc_Locale"=> "en",
"vpc_MerchTxnRef"=> "CLI".$session_id, //This should be something unique number, i have used the session id for this
"vpc_Merchant"=> "TEST111111111111",//Add your merchant number here
"vpc_OrderInfo"=> "XXX".$session_id,//this also better to be a unique number
"vpc_ReturnURL"=> "http://mysite.com/response.php",//Add the return url here so you have to code here to capture whether the payment done successfully or not
"vpc_Version"=> "1");

ksort($testarr); // You have to ksort the arry to make it according to the order that it needs

$SECURE_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";//Add the secure secret you have get

$securehash = $SECURE_SECRET;
$url = "";
foreach ($testarr as $key => $value)
{
$securehash .= $value;
$url .= $key."=".urlencode($value)."&";
}

$securehash = md5($securehash);//Encoding
$url .= "vpc_SecureHash=".$securehash;

header("location:https://migs.mastercard.com.au/vpcpay?$url");
_____________________________________________________________

That's it guyz..

Learn More

How to import a very large MySQL DB to local phpmyadmin (Wamp + Windows)

Unlike in linux OS sometimes you may feel very hard to import a big sized mysql backup to your local machine. So here is an one workaround for that.
  1. First find the config.inc.php file located in the phpmyadmin directory. In my case it is located here: 
    C:\wamp\apps\phpmyadmin3.5.1\config.inc.php
  2. Find the line with $cfg['UploadDir'] on it and update it to: $cfg['UploadDir'] = 'upload'; (Sometimes if you search for the $cfg['UploadDir']  by ctrl+f in that file you may not see it, Just scroll down and find it. Check the image below.
  3. Create a directory called ‘upload’ within the phpmyadmin directory. (C:\wamp\apps\phpmyadmin3.5.1\upload\)
  4. Then place the large sql file that you are trying to import into the new upload directory.
  5. Now go the phpmyadmin of your machine (localhost/phpmyadmin or 127.0.0.1/phpmyadmin/) and go to the db import page
  6. You will notice a new drop down is created there and you can select the placed DB from that drop down (Check the image below).

  7. And then click on GO at the bottom of the import page
That's it guyz :) 

Learn More

ORDER BY Problem in UNION Query

Sometimes when you are doing query you may need to UNION 2 queries and order the results by one column. We cannot do that with the column name

Wrong way 

SELECT name,city FROM students where age > 10
UNION
SELECT name,city FROM teachers where age > 20
ORDER BY city

Correct way 

SELECT name,city FROM students where age > 10
UNION
SELECT name,city FROM teachers where age > 20
ORDER BY 2

From number 2 we are mentioning the position of the required column that needs to be order

Learn More

How to get an image width and height by giving a url or relative path using PHP


Sometimes there can be a requirement to get an images' width and height, may be to re-size them accordingly or whatever, you can use the getimagesize function of php, you can pass the URL of the image (If the image is not in your site) or you can give the relative path (if you want to get the sizes of an image of your site), here how

By URL

list($width, $height, $type, $attr) = getimagesize(http://www.blogger.com/img/blogger-logo-small.png");
$image_width = $width;
$image_height = $height;

By Relative Path


list($width, $height, $type, $attr) = getimagesize(img/blogger-logo-small.png");
$image_width = $width;
$image_height = $height;


Learn More

Good script to get the db backup using php

I think this is better to let run as a cron job (Automated Process) server daily to get the daily backups

backup_tables('localhost','username','password','database');


/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
 
  $link = mysql_connect($host,$user,$pass);
  mysql_select_db($name,$link);
 
  //get all of the tables
  if($tables == '*')
  {
    $tables = array();
    $result = mysql_query('SHOW TABLES');
    while($row = mysql_fetch_row($result))
    {
      $tables[] = $row[0];
    }
  }
  else
  {
    $tables = is_array($tables) ? $tables : explode(',',$tables);
  }
 
  //cycle through
  foreach($tables as $table)
  {
    $result = mysql_query('SELECT * FROM '.$table);
    $num_fields = mysql_num_fields($result);
   
    $return.= 'DROP TABLE '.$table.';';
    $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
    $return.= "\n\n".$row2[1].";\n\n";
   
    for ($i = 0; $i < $num_fields; $i++)
    {
      while($row = mysql_fetch_row($result))
      {
        $return.= 'INSERT INTO '.$table.' VALUES(';
        for($j=0; $j<$num_fields; $j++)
        {
          $row[$j] = addslashes($row[$j]);
          $row[$j] = ereg_replace("\n","\\n",$row[$j]);
          if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
          if ($j<($num_fields-1)) { $return.= ','; }
        }
        $return.= ");\n";
      }
    }
    $return.="\n\n\n";
  }
 
  //save file
  $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
  fwrite($handle,$return);
  fclose($handle);
}

?>

Learn More

WYSIWYG Editor with image upload function for FREE !!!!!

Hey Guyz,

As we all know there's a one problem in free WYSIWYG editors (like Tiny MCE, etc) that do not have the image uploading facility.

normally what we are doing is giving the user to upload the file to server then copy the link and put it as the image url.

Here i have found a solution to upload the file within the WYSIWYG.

First download the OPEN WYSIWYG from http://www.openwebware.com/

Then download the file upload add-on to OPEN WYSIWYG Editor from here : http://www.gallagherwebsitedesign.com/scripts/openwysiwyg-file-upload-addon/

And follow the instructions mentioned in the above link.

Learn More

Export / Import a Perticular table / database in Oracle using command prompt

Export:

To export, type this command in cmd:
>> exp user/[email protected]
It will show many questions, leave it with default answer using hit enter. But, there are the important question, such as:
- (2)U(sers), or (3)T(ables): (2)U >
2 : to export all database under user that mentioned above
3 : to export selected tables only. If 3 choosed, it will appear question what tables that will be exported
- Export grants (yes/no): yes > (type Y or N)
- Export table data (yes/no): yes > (type Y or N)
- Compress extents (yes/no): yes > (type Y or N)

In the rest, make sure that appear message Export terminated successfully without warnings.

Import:

To import full dmp file type this command in cmd:
>> imp user/[email protected] file=emp.dmp log=imp.log full=yes

To import dept table alone type this command in cmd:
>> imp user/[email protected] file=emp.dmp log=imp.log fromuser=user touser=user tables=dept

FROMUSER and TOUSER clause are optional. But in case if used, then create a user in the destination database that is mentioned in TOUSER clause then try importing the dmp file.

In the rest, make sure that appear message Export terminated successfully without warnings.

Learn More