Pages

Friday, September 5, 2014

Cakephp-Overview of Programming Patterns

Active Record Pattern

Active Record Pattern is for those application's which use relational databases.
The interface of an object conforming to this pattern would include functions such as Insert, Update, and Delete, plus properties that correspond more or less directly to the columns in the underlying database table.

Association Data Mapping

An Association data mapping pattern allows Relational object to associate with other Relational Objects the way they are associated in Relational Databases.

Front Controller

The Front Controller Pattern allows handling of all requests to be at a centralized location from where they are redirected specified Request Processors.

MVC

MVC expended as Model View Controller is a pattern where

Model's act as a wrapper classes for Database Table's
Controller's act as wrapper classes for Business Logic
and View act's as file for User Interface
 

Saturday, July 19, 2014

Set up htaccess permissions in ubuntu 14.04

We need to enable mod_rewrite

sudo a2enmod rewrite 

Then we need to restart Apache using following command

 
sudo service apache2 restart 

Then add following lines to /etc/apache2/sites-available/000-default.conf

<Directory "/var/www">
   Options FollowSymLinks 
   AllowOverride All
</Directory>

My apache directory is "/var/www" if yours is different change it to taste

Restart Apache again

sudo service apache2 restart 

Sunday, January 26, 2014

Debian/Linux/Ubuntu-Configure Postfix to use Gmail

Configure Postfix to use Gmail

Install necessary packages first

 sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules  

 Configure Postfix using


 sudo dpkg-reconfigure postfix  


Navigate to Postfix Directory

 cd /etc/postfix  

Open Postfix config file using following command

 sudo gedit main.cf  

Add following lines to it


 relayhost = [smtp.gmail.com]:587  
 smtp_sasl_auth_enable = yes  
 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd  
 smtp_sasl_security_options = noanonymous  
 smtp_tls_CAfile = /etc/postfix/cacert.pem  
 smtp_use_tls = yes  

Now we need to create a file called sasl_passwd


 sudo vi /etc/postfix/sasl_passwd  

Add the following line to the same


 [smtp.gmail.com]:587  USERNAME@gmail.com:PASSWORD  

Configure permissions for sasl_passwd


 sudo chmod 400 /etc/postfix/sasl_passwd  
 sudo postmap /etc/postfix/sasl_passwd  

Validate Certificates


 cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem  

Reload Postfix


 sudo /etc/init.d/postfix reload  

Test Mail from Terminal


 echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com  

Copy of my php.ini mail section


 SMTP = ssl://smtp.gmail.com  
 smtp_port = 587  
 auth_username = usrname  
 auth_password = pwd  
 sendmail_from = from_mail  

Monday, December 16, 2013

PHP-Arrays-Get the occurance of each value in numeric array

Like as always we have a problem we have some prerequisites we will have a function and we will draw some results


Problem and Prerequisites :

We have an array let us suppose array(1,2,1,3,4,5,4,6,3,2,1,2,8,9,3,4,5,3,2,4,6,2) and we want to create a function that checks for number of times value repeats in the array.

So we need and output like

1 repeats 3 times
2 repeats 5 times etc.

Function and Solution :

 <?php
 function get_modes($numarray)  
 {  
   if(!(is_array($numarray)))  
     throw new Exception ('Parameter Not an array');  
   $revarray=array();  
   foreach($numarray as $key=>$value)  
   {  
     if(array_key_exists($value,$revarray))  
     {  
       $revarray[$value]++;  
     }  
     else   
     {  
       $revarray[$value]=1;  
     }  
   }  
   return $revarray;  
 }  
 $myarray=array(1,2,1,3,4,5,4,6,3,2,1,2,8,9,3,4,5,3,2,4,6,2);  
 $navarray=get_modes($myarray);  
 foreach($navarray as $key=>$value)  
 {  
   echo $key." repeats ".$value." times<br/>";  
 }  
 ?>  

Output:

1 repeats 3 times
2 repeats 5 times
3 repeats 4 times
4 repeats 4 times
5 repeats 2 times
6 repeats 2 times
8 repeats 1 times
9 repeats 1 times

Sunday, December 15, 2013

PHP-Image functions

//size of image
getimagesize()
http://www.php.net/getimagesize

//image width
imagesx()
http://www.php.net/manual/en/function.imagesx.php


//image height
imagesy()
http://www.php.net/manual/en/function.imagesy.php

//determine type of an image
exif_imagetype()
http://www.php.net/manual/en/function.exif-imagetype.php

Encrypt data using PHP

Encryption Decryption
AES_ENCRYPT() AES_DECRYPT()
ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
ENCRYPT() N/A
ENCRYPT() N/A
MD5() N/A
OLD_PASSWORD() N/A
PASSWORD() N/A
SHA() N/A
SHA1() N/A
N/A UNCOMPRESSED_LENGTH()

Saturday, December 14, 2013

HTML->Difference between GET and POST methods

POST Method
In Post method we can send unlimited data(This limit is defined by server for example "post_max_size=20M" in Apache)

Data is not shown in URL so it is good for sensitive data

GET Method

In GET method this depends on browser for example IE8 can take about 2048 bytes of data i.e about 2KB

Data is shown in URL so not appropriate for sensitive data