Category : "Coding"

All kinds of Programming.

Code a network packet sniffer in PHP

Example of a packet sniffer is Wireshark. Packet sniffers pick up the packets going in and out of a system and analyse them and present them to user for further analysis. In this post we are going to code a simple packet sniffer in php. The basic theory this packet sniffer is that , raw packets can sniff without much effort ...

Php get zip error message from error number

Php functions like zip_open return an error number if they fail. To get the corresponding error message from the error number , use the following function. function zip_error_message($errno) { // using constant name as a string to make this function PHP4 compatible $zipFileFunctionsErrors = array( 'ZIPARCHIVE::ER_MULTIDISK' => 'Multi-disk zip archives not supported.', 'ZIPARCHIVE::ER_RENAME' => 'Renaming temporary file failed.', 'ZIPARCHIVE::ER_CLOSE' => 'Closing zip archive failed', 'ZIPARCHIVE::ER_SEEK' => ...

Get http request headers in php

When a browser makes a request to a php script, the browser sends some http headers which can look like this : Host: localhost Connection: keep-alive User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: UTF-8,*;q=0.5 Cookie: username=admin; password=21232ffc3; PHPSESSID=o5m4e2td1m66c4pkjdag9vs0u2 The php script under request , may want to access these http headers. PHP has a method getallheaders() which provides ...

Writing a Script to Validate HTML/CSS of a Webpage in Ruby

In this post, I am going to write HTML and CSS Validators in Ruby and PHP. W3C HTML and CSS Validators basically check the validity of the URL supplied to it. It is always a good idea to write completely valid HTML and CSS for several reasons. The W3C HTML Validator checks the markup validity of Web Documents in HTML, XHTML, etc. ...

PHP get adsense earnings and reports

In this article we are going to login into Google Adsense and retrieve earnings. Google Adsense now has a new interface and so needs a different kind of coding. In this example we shall fetch "yesterday's" earnings sitewise. Create a Report to be fetched : First open the sitewise report in the Performance Tab in the new interface of Google Adsense at ...

PHP get DNS Nameserver , Cname , MX , A records of a domain

PHP has a useful function called dns_get_record that can be used to get different types of records for a give domain , very easily. Nameserver - NS Records : $ php -a Interactive shell php > print_r(dns_get_record('www.binarytides.com' , DNS_NS)); Array ( => Array ( ...

Parse MVC style urls in PHP

If you have used codeigniter or some mvc php framework then you might be aware of urls like www.yoursite.com/index.php/class/method/param1/param2?a=b&c=d or www.yoursite.com/class/method/param1/param2?a=b&c=d if you use mod rewrite to add the index.php The htaccess code could be like this : <IfModule mod_rewrite.c> #Start the rewrite engine RewriteEngine on #If requested thing is not a file or directory , then rewrite RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ...

Suppress Errors & Warnings With @ operator in PHP

The at sign (@) is an error control operator in PHP. You can suppress errors, warnings and notices using @ operator in PHP. It is quite common to prefix function calls with @ to suppress errors like this - <?php @mysqli_connect($host, $user, $pass, $db_name); # If the connection is not established for some reason, then the error will be suppressed @getimagesize('lol.png'); # If ...

Quick Tip: Installing Ruby Gems in the user’s Home Directory

Note: The Operating System in use is Ubuntu Linux (11.04) My Gem Environment - $ gem env RubyGems Environment: - RUBYGEMS VERSION: 1.8.11 - RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.9.1 - RUBY EXECUTABLE: /usr/local/bin/ruby - EXECUTABLE DIRECTORY: /usr/local/bin - RUBYGEMS PLATFORMS: - ruby - x86_64-linux ...

Write a simple PHP Hit Counter Script

In this tutorial, I am going to show you a simple way to write a Hit Counter script in PHP to save and display the number of visits to your website. We will basically store and increment the hits in a file, that can be used to display the total hit count as well. The code to store the hits follows - <?php class ...



Connect with us