Monthly Archives: October 2010

Palindromic number with Python

A palindromic number is a symmetrical number which remains same when it’s digits are reversed.

Example : 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 11 , 22 , 33 , 44 , 55 , 66 , 77 , 88 , 99 , 101 , 111 , 121 , 131 , 141 , 151 , 161 , 171 , 181 , 191 , 202……..

Today I will show you how to check if a number is a palindromic number, how to get the next palindromic number of a number, how to get the previous palindromic number of a number.

Function is_palindromic :

[python]
def is_palindromic(number):
string = str(number)
if number == int(string[::-1]):
return True
else:
return False
[/python]

This function will return true for palindromic number otherwise it will return false.

Example :

[python]
## Example One…
if is_palindromic(20):
print "The number is a palindromic number."
else:
print "The number is not a palindromic number."
//// It will print "The number is not a palindromic number."
## Example Two…
if is_palindromic(22):
print "The number is a palindromic number."
else:
print "The number is not a palindromic number."
//// It will print "The number is a palindromic number."
[/python]

Function next_palindromic() :

[python]
def next_palindromic(number):
i = 0
while i < 1:
number = number + 1
string = str(number)
if number == int(string[::-1]):
i = 1
return number
[/python]

This function will produce the next palindromic number of a number.

Example :

[python]
print next_palindromic(11)
//// It will print 22
print next_palindromic(22)
//// It will print 33
[/python]

Function prev_palindromic() :

[python]
def prev_palindromic(number):
i = 0
while i < 1:
number = number – 1
string = str(number)
if number == int(string[::-1]):
i = 1
return number
[/python]

This function will produce the previous palindromic number from a number.

Example :

[python]
print prev_palindromic(22)
//// It will print 11
print prev_palindromic(2)
//// It will print 1
[/python]

How To Make Contact Form Using Codeigniter

Codeigniter is a famous php framework which id enriched with verious facility. You can use third party library , helper with it. You can easily extend default libraries. Above all you will be able to use it as you like.

This blog post is about making a basic contact form using codeigniter. This tutorial will help the novice those who are interested to learn basics of codeigniter.

Configuration

[+] Open index.php

=> Change the value of $system_folder and $application_folder

[+] Open <application_folder>/config/config.php

=> Change $config['base_url'] = “http://example.com/”;

[+] Open <application_folder>/config/routes.php

=> Change $route['default_controller'] = “welcome”; to $route['default_controller'] = “contact”;

[+] Open <application_folder>/config/autoload.php

=> Change $autoload['helper'] = array(); to $autoload['helper'] = array(‘url’);

Continue reading

PHP Security Issue : $_SERVER

Security is one of the most important thing for any kinds of web site. Web developers work hard to ensure better security for their site but sometimes they don’t notice some security leaks and then hackers take chance.

SQL injection and XSS is most common attack nowadays. The hackers input vulnerable code to attack a site. In PHP we generally escape $_GET ,$_POST , $_SESSION , $_COOKIE variables. But only escaping $_POST , $_GET , $_SESSION , $_COOKIE variables doesn’t ensure 100% security of your site.

Continue reading

HOTTURL – url shortener based on Codeigniter

image of url shortener

URL Shortener

Nowadays Codeigniter is one of the most popular framework which supports both PHP4 and PHP5. Few days ago I was reading a documentation of it. Then an idea came to my mind. I decided to make an url shortener using Codeigniter. I found a library to make short url. It took a very little time to make it. I named it HOTTURL. Download it from google code. You can change language and design of it. I hope everyone will like it. I will release and update version as soon as possible.