Archive for the ‘php’ Category

ASP? PHP? JSP? What-Else-P?

These 3 technologies are the most famous these days in the web programming world. Sometimes you’d ask yourself, which of these 3 is the best? The answer, there’s none. It really depends on a lot of factors to decide which technology is best to use. In my experience, these are the following…

In the case of server setup, ASP would be easiest as installing IIS (Internet Information Server) is very easy. Just add this under add/remove programs, add/remove windows components and check the checkbox of Internet Information Services (IIS). Once the server installed, you can then place all your ASP pages under it default working directory c:\inetpub\wwwroot. I said ASP is easiest because you do not need to download the IIS installer. It is part of your OS installer so you can install it anytime. With JSP, you can download Apache Tomcat which is free. Installation is not a hassle and you then place all your JSP files right away under the server’s default webapp directory. Mostly when developers work with JSP, they are usually packaged as a web application archive file (.war). As for PHP, it’s the most hassle. There are so many things to configure before you can get PHP running. I use Apache HTTP Server for PHP but you would have to download PHP and configure its plugin to be used by the server to interpret PHP code.

In the case of language experience, if you already know VB/VBScript, quickest would be to go for ASP since it supports VBScript. If you know Java, then you go for JSP. If you know C, then PHP is for you. If you have patience to learn all of them, this is the order in which I rate each technology according to easiness: ASP/PHP (tie), JSP.

In the case of performance issues, there is really no clear winner for me. I’ve read a lot of articles that often compares the performance between these technologies. The secret for good performance is how well you design your system. If you messed it up real good, then good luck with your web application. And of course, you would have to have a fast server in order to process transactions efficiently, else the good design solution would be useless.

As far as I know, Servers for PHP do not have database pooling. As do ASP. If there are any now, please let me know. I’m pretty sure JSP’s server like Apache Tomcat supports database pooling because I have tried using it. I searched the same thing for PHP but could not find any in Google. Database pooling gives you a huge advantage on resource management. Click here to read more about it.

There may be other issues that need to be put into consideration when comparing these 3. For me though, these are it.

Donations appreciated. Every little $ helps. Or click Google +1

PHP Mask Credit Card Number

This method masks credit card numbers and shows only the last 4 digits. I also forgot where I got this method from. If you wish to change the number of last digits shown, just modify the last parameter of the method. The part where it says $l = 4.

function maskCC($n, $b = 4, $p = 16, $m = 'X', $l = 4) {
  // $n = 'card number: 1234567890123456' string
  // $b = break into how many in each chunk?
  // $p = pad to what length?
  // $m = mask character?
  // $l = leave how many numbers showing?
  preg_match("/card number:\s*(\d+)[^\d]*/i", trim($n), $matches);
  $pattern = "/card number:\s*(\d+)/ie";
  $replacement = " implode('-', str_split( substr_replace( str_pad('$1', '$p', '0', STR_PAD_LEFT), str_repeat('$m', $p-$l), 0, $l * -1 ), $b) ); ";
  return preg_replace($pattern, $replacement, trim($n));
}

// use the function
var_dump(maskCC("\ncard number: 1222233334444\n"));

Donations appreciated. Every little $ helps. Or click Google +1

PHP Encrypt Decrypt using Base64

Here are two methods to encrypt and decrypt using Base64. I forgot where I got this from but these 2 methods are pretty handy. Make sure you remember your key as your string will be encrypted and decrypted according to what you specify as key. Key is a string here.

Usage is as follows:
$encrypted = encrypt("to encrypt string", "chitgoks");
$decrypted = decrypt($encrypted, "chitgoks");

$decrypted will return to encrypt string.

function encrypt($string, $key) {
  $result = '';
  for($i=0; $i<strlen($string); $i++) {
    $char = substr($string, $i, 1);
    $keychar = substr($key, ($i % strlen($key))-1, 1);
    $char = chr(ord($char)+ord($keychar));
    $result.=$char;
  }

  return base64_encode($result);
}

function decrypt($string, $key) {
  $result = '';
  $string = base64_decode($string);

  for($i=0; $i<strlen($string); $i++) {
    $char = substr($string, $i, 1);
    $keychar = substr($key, ($i % strlen($key))-1, 1);
    $char = chr(ord($char)-ord($keychar));
    $result.=$char;
  }

  return $result;
}

Donations appreciated. Every little $ helps. Or click Google +1

Related Posts with Thumbnails