Category: PHP

cakephp 3 social login — Site Title

Here is the link for social login in cakephp3


HOW  XSS attack handled by different PHP frameworks?


Open place for tech lovers

As we know PHP is Open Source, so we can play over it. It also has list of Frameworks to follow for web development.But, while doing development we have to take care about XSS attacks. Now, Question arrise 🙂

What  is XSS?

Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into trusted web sites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in form of a browser side script, to a different end user. These attacks can occur anywhere a web application uses input from a user within the output it generates without validating or encoding it.

An attacker can use XSS to send a malicious script to an unsuspecting user. The end user’s browser has no way to know that the script should not be trusted, and will execute the script. Because it thinks the script came…

View original post 416 more words

Passing data from CakePHP component to a helper


Sourabh Jain

My query was :- Is there any elegant way to pass data from a component to a helper?
Yes, the same way you pass any data to the helper. In your view.
Inside your component I would do something like the following. The beforeRender() action is a CakePHP component callback.

publicfunction beforeRender(Controller $controller){
    $yourVars ='some data';
    $goHere ='other stuff';


Then in your view you can pass the data off to your helpers just like normal.

// view or layout *.ctp file

View original post

How to paginate multiple results in CakePHP?


For Latest Tech Updates Go To

Sourabh Jain

Here is my solution. In your controller :

function index(){// Your default model
    $this->set('model1', $this->paginate());// Pagination for model2
    $this->set('model2', $this->paginate('Model2'));}

In your view :

// Display your model1 data, and then for prev and next 
echo $paginator->prev($options = array('model'=>'Model1'));
echo $paginator->next($options = array('model'=>'Model1'));
The point is input your model name to Controller's paginate method and to Paginator's link method (sort, prev, next).

// Display your model2 data, and then for prev and next 
echo $paginator->prev($options = array('model'=>'Model2'));
echo $paginator->next($options = array('model'=>'Model2'));

View original post

Page borders in all pages Using TCPDF

You can add borders to all pages in pdf generated using TCPDF by simple two steps.

  • Create a new class extend from TCPDF class
  • Override the Header method. (Header method is called on a generation of each new page in TCPDF)
class PTCPDF extends TCPDF
     protected $processId =0;
     protected $header ='';
     protected $footer ='';
     static $errorMsg ='';
      * This method is used to override the parent class method.
     public function Header()
          $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true);

          $this->SetLineStyle( array('width'=>0.40,'color'=> array(0,0,0)));

          $this->Line(5,5, $this->getPageWidth()-5,5); 

          $this->Line($this->getPageWidth()-5,5, $this->getPageWidth()-5,  $this->getPageHeight()-5);
          $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5);
          $this->Line(5,5,5, $this->getPageHeight()-5);

For Latest Tech Updates Go To

Retrieve Data By Multiple Order Priority In CakePHP

How you cab retrieve data from database by multiple field order priority………?

In cakePHP you can do easily as shown in below example.

In the following pagination query will output as Model first_name in Ascending order and Model last_name in Descending order.

$this->paginate = array(
        'conditions' => array(
                        ‘Model.created_date <‘  =>  ‘2014-01-01’
        'order' => array(
            'Model.first_name'  => 'ASC',
            'Model.last_name'  => 'DESC',


MySQL database backup to Email and to FTP Server

Database is very essential and important part of any dynamic system or application. We need to take backup of database time to time. This can be done using the user interface like phpmyadmin on regular basis and stored in a secure location.
The manual process is time consuming and there are change when you forget. We can automate this by making a php application that will backup mysql database and upload it to server using FTP and also mail the backup to user.

1) Mysql database dump can be taken using command below

mysqldump –opt -h (hostname) -u (database_userbname) –password=(database_password) )(databasename) | gzip > (filename);

This command can be executed using php function passthru() and it will generate backup file of database.

2) Now upload backup to FTP
To upload database to FTP php has some functions like ftp_connect(), ftp_login(), ftp_nb_fput(). using these function backup can be uploaded to FTP.

3) Email backup
Email backup using php function mail().

Click here to download the script.