Thursday, January 1, 2015

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..

Saturday, August 30, 2014

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 :) 

Wednesday, June 26, 2013

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

Monday, May 6, 2013

To check whether a field contain duplicate values in the database via sql query


Using below queries you can get the duplicate name field details of names table

SELECT id, name, COUNT( name) 
FROM names
GROUP BY name
HAVING (
COUNT( name) >1
)

Sunday, March 3, 2013

Replace a text with something else by a SQL Query

Syntax :

UPDATE Table SET Column = Replace(Column, 'find value', 'replacement value') WHERE xxx


Example :

UPDATE `links` set url = replace (url,'http://www.google.com','http://www.yahoo.com') where url != ''

Thursday, December 6, 2012

Automatic form submission after specified time using javascript

Put following code after your form closing tag

<script language="Javascript">
  function doSubmit() {
//asubmit is the name of the SUBMIT button in the form
  document.yourForm.asubmit.click();
  }
  //auto submit after 5 second
  setTimeout("doSubmit()",5000);
  </script>

Tuesday, November 20, 2012

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;


Wednesday, May 30, 2012

Make the url from http to https using htaccess file

You have to upload a .htaccess file to the root of your web site with following code


<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{SERVER_PORT} ^80$

RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

</IfModule>

Tuesday, May 29, 2012

Cannot query inside the while loop in PHP ? Here is the solution

Here is the solution


$sql = "select id from student where classId = 5";
$view = mysql_query($sql);

while($row = mysql_fetch_array($view))
{
      $array[] = $row;
}


foreach($array as $arow)
{

$sqli = "insert into course (studentId,course) values (".$ arow ["id"].",'".Maths.'")";
mysql_query ($sqli);

}

Monday, March 26, 2012

How to increase the size of tinymce applied textarea

Go to tiny_mce/tiny_mce.js and find for o.deltaHeight||0 and change that line to acccording to the height you want like below

h=Math.max(parseInt(h)+(o.deltaHeight||0),100); Usual line, 100 is the default height, you can change it as you want like

h=Math.max(parseInt(h)+(o.deltaHeight||0),300);

Wednesday, February 8, 2012

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);
}

?>

Friday, December 23, 2011

Why wasting time on validation? Easy and proper way to validate your forms by spry validation option in Dreamviewer CS5

Is it a hectic to implement validations on your html forms ? here is a good solution for it, anyone can do this even you do not have the any knowledge on Javascript. watch below video.. cheers