Browsing articles from "October, 2011"
Oct
29
2011

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 – The script above basically creates the target directory and the file to which [...]

Oct
24
2011

Make a TCP Connect port scanner in PHP

A port scanner is a software application designed to probe a server or host for open ports. We earlier made a TCP Connect port scanner in C here – http://www.binarytides.com/blog/tcp-connect-port-scanner-code-in-c-with-winsock/ and here – http://www.binarytides.com/blog/tcp-connect-port-scanner-with-linux-sockets-bsd/ Now we shall try making the same in PHP. The code is very simple : Using fsockopen Output : The above code uses fsockopen to connect a host on a port , and if the connection is established then it returns [...]

Oct
23
2011

Setup Internet Connection Sharing on Ubuntu Linux with Firestarter

Firestarter is an easy to install firewall application for Ubuntu which also has to the option to enable Internet Connection Sharing at the click of a mouse. Install : sudo apt-get install firestarter Launch the application firestarter. The wizard will come up on the first run. Enable Internet Connection Sharing in the wizard, and start the firewall. Now other computers connected to this machine should be able to access internet , provided they all have [...]

Oct
23
2011

Top Port Scanners on Ubuntu Linux

Here is a list of port scanners that work on Ubuntu/Linux. 1. Angry IP Scanner Download and Install from http://www.angryip.org/ Fast and easy to use network scanner and port scanner. To scan ports got to Tools > Preferences > Ports > Port Selection Enter the ports you want to scan Start the scan. 2. nmap – network mapper Install : sudo apt-get install nmap Nmap is a utility for network exploration or security auditing. It [...]

Oct
23
2011

PHP best way to check if file is an image

The getimagesize function of php provides lot of information about an image file , including its type. The type can be used to check if the file is a valid image file or not. To check if a file is an image or not, use the function : $a[0] and $a[1] are the width and height of the image. $a[2] has the image type. Other image formats include : [IMAGETYPE_GIF] => 1 [IMAGETYPE_JPEG] => 2 [...]

Oct
23
2011

PHP manage multiple cronjobs with a single crontab entry

In many php applications there are multiple tasks that need to be run via cron at different times. The simple approach would be to add all the tasks to the crontab. However this approach has many drawbacks : 1. Multiple entries in crontabs means more time and effort needed to edit the crontab and maintain it. 2. The crontab command has to be used everytime a change is to be made. 3. If the script [...]

Oct
23
2011

PHP check if a timestamp matches a given cron schedule

Above is an example of a given timestamp. And a cron schedule can look like this 0 5 * * * – which means run everyday at 5 hours and 0 minutes. Now in a php application you may need to test if a given timestamp , say 1319362432 matches a given cron schedule like 0 5 * * *. Here is a quick php function that can do this task. How does it work [...]

Oct
23
2011

PHP strtotime in 64 bit environment

The strtotime function is used to convert a date in various formats to a timestamp. However its behaviour is different based on architecture it is running on, whether 32bit or 64bit. Lets take a few examples : In 64 bit environment Over here we can see that strtotime is producing timestamps for far dates like 30-01-2100 and 30-01-1000 and even 00-00-0000 whereas on a 32 bit machine it would do this : Output : So [...]

Oct
23
2011

How to perform IP whois from terminal

In a previous article http://www.binarytides.com/blog/how-to-perform-domain-whois-from-terminal/ we saw how we can perform a whois for a domain name from the terminal/console. Now here we shall see how to perform a whois for an ip address from the terminal. Get your ip address from http://www.ipmango.com/. I got this IP : 59.93.210.154 Little Theory The information about any ip or ip range is stored in the Regional Internet Registry. The 5 main registries are : 1. APNIC – [...]

Oct
22
2011

How to perform domain whois from terminal

According to Wikipedia : WHOIS (pronounced as the phrase who is) is a query and response protocol that is widely used for querying databases that store the registered users or assignees of an Internet resource, such as a domain name, an IP address block, or an autonomous system, but is also used for a wider range of other information. The protocol stores and delivers database content in a human-readable format. The Whois protocol is documented [...]

Pages:123»