September 29th in PHP Scripts by pbu .

How URL shortening scripts work?

I have been quite intrigued with the working of these URL shortner scripts and surprisingly most of them employ an ingenious solution to compress the URL to a shortened one.

http://example.com/fe45 ——-> http://corpocrat.com/blah/page.htm

The answer is base36 encoding. why base36? because it can contain 26 alphabets and 10 numbers in the output. This is surprisingly simple way of encoding a URL.

Base 36 is nothing but, you keep on dividing a number by 36, collect its reminders (or modulo) and map them …

September 28th in Linux/Unix, PHP Scripts by pbu .

How to check IPs on same subnet?

How to check IPs on same subnet?

In many cases, you might want to check whether an ip address falls under a same subnet or not. It can be done both in perl and php using the Network library.

For PHP use Net IP4 library
For PERL use Net::IP library

<?php
// check for IP falls in same subnet or not
include("Net/IPv4.php");

$objIP = new Net_IPv4();

echo $objIP->ipInNetwork("192.xx.xx.xx", "192.xx.xx.x/24") ? "Same Subnet" : "Outside the Subnet";
?>

In perl you can use Net::IP module

#!/usr/bin/perl

use NetAddr::IP;

my $netwrk = NetAddr::IP->new(‘192.xx.xx.x/24′);
my $ip …

September 22nd in Linux/Unix, PHP Scripts by pbu .

HOWTO: Install PEAR for php in Linux

Install PEAR for php in Linux

It is very easy to install PEAR package for php. It lets you to install many many php extensions easily without compiling the source packages.

If you get

pear – command not found

then it means pear is not installed in your server. To install it just follow the steps below at the command prompt.

Download the installation php file from http://pear.php.net/go-pear.

wget http://pear.php.net/go-pear

Rename to php file

cp go-pear go-pear.php

Run the php script from commandline.

php go-pear.php

and you will see …

August 18th in Linux/Unix, PHP Scripts by pbu .

Automatic Face Detection in Photos with PHP

I have always wondered how to detect faces automatically with php script. I have seen in many photo sharing and social network sites automatically detect a face and tag a name after being uploaded.

In this article, i will explain how possible this task can be achieved with simplicity with OpenCV and PHP Facedetect extension. Both are free to download and opensource.

Goal

To auto detect faces in a photo and draw pink box around the faces with a php script running a …

July 28th in PHP Scripts by pbu .

How to filter & escape data from Injection attacks in PHP!

Ask any security expert! He will say you should always filter POST and GET data by escaping them before insertion into the database. In that way your scripts can be safe from SQL injection attacks.

Many php programmers are so lazy and just directly insert the POST data without filtering it like

mysql_query("INSERT into `users` (`name`,`email`) VALUES (‘$_POST[name]‘,’$_POST[email]‘)"):

which is truly a bad example of not checking input data.

A very good way to clean user input is using mysql_real_escape_function() which is a good …

July 27th in Linux/Unix, PHP Scripts by pbu .

Using htaccess to redirect domain without http://

Using htaccess to redirect domain without http

A very simple problem made me to sweat a lot. I have a site where users post their website link and most of them are so dumb and just wont put http:// in their domain and they submit just like www.domain.com.

If the link goes live in my website it wont get redirected and merely 404 file not found error pops up and the URL looks like http://mysite.com/www.domain.com

i know i could check http with regular …

July 6th in PHP Scripts by pbu .

PHP script using mail() vs smtp?

PHP script using mail vs smtp method for emailing

I have often confused about the which method to use for sending mails with a php script. I have used php mail() function in many projects and it is often slow, which is because this function opens sockets everytime you call this function. This doesnt work if you are mass emailing and smtp or sendmail is the way to go.

The best and fast way of sending email is using

- SMTP (faster)
- …

June 23rd in PHP Scripts by pbu .

PHP script to convert text string to image

PHP script to write email address into a image

I was after a php script that dynamically converts text to image and finally i decided to code on my own. It also does convert small length text to image like names, emails etc..

This script automatically calculates the width of text into pixels inserts the PNG or gif image.

this is a string to <
>

To call the script for dynamically generating an image just use the html code

<img src="txt2img.php?text=<? echo $str ?>" …

May 25th in PHP Scripts by pbu .

Retrieve select box value from database using PHP

Retrieve select box value from database using PHP

I have been in many situations in designing a html form where i want the value stored in database selected in select box when editing the user data.

For example if i have colors like Red, Green, Blue, Yellow, Violet shown in selectbox and if the user selected Green and previously stored in database, then we need to show the select box with Green as selected value. This kind of situation arises, while editing …

May 24th in PHP Scripts by pbu .

how to store and retrieve checkbox value in php?

how to store and retrieve checkbox values in mysql database with php

I was working on a project and i had landed in an awkward situation, where i have to save the tick box values in a database and once done, i had to retrieve those values and present it to the user for editing. i searched everywhere on the web on how to store and retrieve check box values and the answers are hard to find. So i have decided …

 Page 1 of 5  1  2  3  4  5 »