Tag Archives: php
Setup Nginx + php-FPM + apc + MariaDB on Debian 7 – The perfect LEMP server
Install and configure Apache and PHP with cgi on Ubuntu or Debian
Setup Apache and Php with mod_fcgid on Ubuntu/Debian
Mod Fcgid Mod Fcgid is an apache module that enables it to talk to fastcgi enabled application. It can be used to setup with apache to run php over fastcgi. It is an alternative to the older mod_fastcgi and has some differences with it. In this post we shall be setting up apache with php… Read More »
Output buffering in php and apache
Output Buffering Output buffering is processing mechanism where the output being generated by a program is held in a place till its size reaches a limit or the generation is complete. Only after, will the output be send to its destination. In php for example, doing and echo generates some output. Now this output might… Read More »
Install and configure Apache and php with mod fastcgi on Ubuntu/Debian
An overview of apache mpms and php server apis
Apache + Php When setting up an apache+php server to run your php applications, there are lots of configuration parameters to deal with. The most important is the php Server Api (sapi). It determines how exactly is apache going to run the php scripts. Along with the php sapi another important thing to select is… Read More »
Php – Do not rely on set_time_limit too much
Php set_time_limit Php has a function called set_time_limit which can be used to dynamically adjust the maximum execution time permitted to a script. It allows specifying the time in seconds and limits the script execution time to that many seconds. The set_time_limit function whenever called, effectively extends the script execution time by that many seconds…. Read More »
Php reverse shell with netcat
How to modify a SoapClient request in PHP
SOAP and PHP SOAP is a protocol to exchange objects over http. It is used to implement apis and the data being exchanged is in xml format. Sometimes it might be required to modify the soap request to add custom http headers for example. Since SoapClient is a class, it can be extended and the… Read More »
Php – Fix “Input is not proper UTF-8, indicate encoding” error when loading xml
When loading xml files in php through simplexml_load_string or domDocument class, sometimes an error like this might popup Warning: DOMDocument::loadXML(): Input is not proper UTF-8, indicate encoding ! OR Warning: simplexml_load_string(): Entity: line 93: parser error : Input is not proper UTF-8, indicate encoding ! The error occurs when the xml has some invalid characters… Read More »
Php – How to fetch gzipped content over HTTP with file_get_contents
The file_get_contents function is often used to quickly fetch a http url or resource. Usage is very simple and appears like this $content = file_get_contents('http://www.google.com/'); However the file_get_contents does not get the contents compressed. It requests the server to send everything in plain text format. Most websites are capable of serving compressed content, if they… Read More »
Socket Programming with Streams in Php – How to Code Client and Server
Socket Programming Socket programming involves connecting to remote machines on LAN or over the internet using ip addresses and port number. For example google.com has an ip “173.194.36.3” and runs http server on port 80. So a socket application can connect to that ip address on that particular port number and start data communication. Socket… Read More »
Parse the user agent with ua-parser in php – detect browser, os and device
In your web application you might need to parse the user’s user-agent string to find out the browser/OS/device being used. This is necessary specially when your webapp tries to adapt to the user’s platform in a better way. For example a different layout for mobile device or restricted features/graceful degradation on a non supporting browser…. Read More »
How to download a file using Curl in PHP – Code Snippet
Download a File using Curl Here is a quick curl snippet for php, that can download a remote file and save it. <?php set_time_limit(0); // File to save the contents to $fp = fopen ('files2.tar', 'w+'); $url = "http://localhost/files.tar"; // Here is the file we are downloading, replace spaces with %20 $ch = curl_init(str_replace(" ","%20",$url));… Read More »
How to compress images in Php using GD Library
Php applications might need to do some image processing if they are allowing users to upload pictures of somekind. This can include cropping, watermarking, compressing etc. To compress an image the quality needs to be adjusted. Here is a code example of how to do it: function compress_image($src, $dest , $quality) { $info = getimagesize($src);… Read More »
Convert excel to csv in php
When working with data import and export for example, file formats like csv and excel are commonly used. Data can be exported to csv format and imported elsewhere. Also data might be entered manually in an excel file and then imported in the database. So there might be a need to convert excel files to… Read More »
Generate qrcode and pdf417 barcodes in php with tcpdf
Tcpdf is a pdf creation library for php that is written in pure php and works without the need of any external library. It also has the feature to generate 2d barcodes like qrcode and pdf417. The 2d barcodes can store much more information than the 2d ones like code39 and ISBN. It is recommended… Read More »
Php – Output content to browser in realtime without buffering
Consider a long running php script that does many tasks and after each task it outputs the status. echo 'Task 1 complete'; …. some delay … echo 'Task 2 complete'; …. more delay and more tasks … Now for such scripts it may be important to load the contents in browser as quickly as they… Read More »
Php reverse shell with metasploit
After hacking a web application or server to such an extent that you can upload files to it, the next thing to try is get a proper shell on the system. The most common approach is to create reverse shells. In this approach first a listener program is run on the hacker’s machine and then… Read More »