Skip to main content


Showing posts from December, 2011

PHP ssh2_connect() not working?

Most of the times we use ssh2_connect() function to connect and download files from remote server without using ftp. Sometimes it doesn't work. Please note some useful tips: 1) Make ensure that openssl is enabled and libssh2 is installed on your server. 2) Even after that when calling ssh2_connect() function if you are getting errors like following: [Sat Dec 03 19:30:35 2011] [error] [client] PHP Warning: ssh2_connect(): Unable to connect to on port 22 in /var/www/html/connection.php on line 9 [Sat Dec 03 19:30:35 2011] [error] [client] PHP Warning: ssh2_connect(): Unable to connect to in /var/www/html/connection.php on line 9 It means apache is not allowed to send packets using tcp. Then run the following command from your server console: //Allow HTTPD scripts and modules to connect to the network using any TCP port. # setsebool -P httpd_can_network_connect 1 here P stands for permanent. Sometimes th

PHP redirection through header() function not working?

header ( "Location:" ); While using header function sometimes you got the error like: ' Cannot add/modify header information – headers already sent by…'  To avoid such situation you can use output buffering or just make sure that nothing was sent to the client.   Remember also that headers MUST be sent before any output is started. There are no exceptions from this rule, in fact you cannot even sent a blank line to the output, executing code like this: echo ""; 

How to write PDF file in PHP?

PHP is a dynamic web development language with some surprising capabilities. It can even create PDF documents on the fly, if right third party library is available. Here in this post we are using FPDF library. You can download the same from here . Following is the example how you can write a simple pdf file using this library: "pdf.php" <?php     //Connection to the database     $link = mysql_connect("localhost","root","");     if (!$link) {         die('Could not connect: ' . mysql_error());     }     mysql_select_db("practice");     //end of database connection code     require('fpdf.php');     $pdf=new FPDF();     $pdf->AddPage();     $pdf->SetFont('Arial','B',10);     $pdf->Cell(50,3,"Learn how to write PDF Files in PHP");     $pdf->Ln();     $pdf->Ln();     $pdf->SetFont('Arial','',6);     $text = "A