Friday, September 18, 2009

Turnoff autocomplete or disable cache in HTML pages

In some pages(like creditcard payment page or any other authentication page) we have to avoid the drop down which was appeared below the input text elements. This is active by default in a web browser.

To avoid the autocomplete of input text elements add autocomplete="off" attribute to your input element.
For example..



<input id="creditcardnumber" name="creditcardnumber" autocomplete="off" type="text">


Labels: , , ,

posted by adityachandra @ 1:56 PM, ,


Monday, May 4, 2009

Encryption and Decryption in PHP

Hello Readers( if any ;) ) . Encryption and Decryption is one of the most useful and widely used technique when we want to pass values through URL (or) for encrypting the sensitive data. I googled over the Internet for these functions and finally i got them. Here are the two simple functions to encrypt and decrypt the the data with a key (or) password.

First, let us see the ENCRYPT function

/** Input Parameters are

** $string- The string you want to encrypt

** $key- string(it's like a password)

**/

function encrypt($string, $key) {
$result ='';
for($i=0; $i

//enode the result using base64 function for more security
return base64_encode($result);
}

?>

Now head on to DECRYPT function.

/** Input Parameters are

** $string- The string you want to encrypt

** $key- string(it's like a password)

**/

function decrypt($string, $key) {

$result ='';

//decode the result using base64 decode function

$string = base64_decode($string);
for($i=0; $i

?>

USAGE:

//Here we are encrypting "foobar" using the key "wordpress"

$encoded = encrypt("foobar","wordpress");

//Here we are decrypting "foobar" using the key "wordpress"

$decoded= decrypt($encoded,"wordpress");

Labels: , , ,

posted by adityachandra @ 12:55 PM, ,


Wednesday, April 29, 2009

Adding days to a date in PHP

Here is the small and most useful function to add days to a particular date.

function dayadd($g,$dayYmd) {
//add $g days to $dayYmd (date is in YYYY-MM-DD format)
$d = strtotime($dayYmd);
$cc = 24*60*60*$g + 60*60 + $d;
return date("Y-m-d",$cc);
}
?>

Labels: , ,

posted by adityachandra @ 12:29 PM, ,


Saturday, September 20, 2008

Importing Yahoo Contacts Using CURL and PHP

Here is the code to import yahoo address book using curl and php. This is very helpful if we want to import the contacts into our site from yahoo. Give a try and please comment on this script.

function yahoo_login($email_id, $password)
{
// Create URL
$url = "https://login.yahoo.com/config/login?";
$query_string = ".tries=2&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us&.bypass=";
$query_string .= "&.partner=&.u=4eo6isd23l8r3&.v=0&.challenge=gsMsEcoZP7km3N3NeI4mX";
$query_string .= "kGB7zMV&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.";
$query_string .= "done=http%3A%2F%2Fmail.yahoo.com&login=$email_id&passwd=$password";
$url_login = $url . $query_string;
// End Create URL

// Execute Curl For Login
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url_login);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_HEADER , 1);
ob_start();
$response = curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
unset($ch);
// End Execute Curl For Login

// Call Address Book Page Through Curl
$url_addressbook = "http://address.yahoo.com/yab/us";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_HEADER , 1);
curl_setopt($ch, CURLOPT_URL, $url_addressbook);
$result = curl_exec ($ch);
curl_close ($ch);
unset($ch);
// End Call Address Book Page Through Curl

// Manuplate String
$result = preg_replace("([\r\n\t])", " ", $result);
$result = strip_tags($result);
$arr_result = explode(" ", $result);

$arr_filter = array();
for($i=0; $i{
if(strpos($arr_result[$i], '@') > 0 && strpos($arr_result[$i], '.') > 0)
{
if(!in_array($arr_result[$i], $arr_filter, TRUE))
$arr_filter[] = $arr_result[$i];
}
}
// End Manuplate String

// Return Result Array
return $arr_filter;
// End Return Result Array
}
$res = yahoo_login("username","password");
var_dump($res);
?>

Labels: , ,

posted by adityachandra @ 10:53 PM, ,


PHP Cheat Sheet

What is a Cheat Sheet ? I too don't know before I came across this php cheat sheet. It is a one page reference of widely used PHP functions and espescially regualr expression(I love it..but trying to learn). Here is the link that you can download the PHP cheat sheet of V2 in both PDF and PNG formats. Hope this helps some body some where :-)

PHP Cheat Sheet

Labels: , ,

posted by adityachandra @ 4:10 PM, ,


Wednesday, June 4, 2008

Getting File Permissions in PHP

PHP has an built-in function to know the permissions assigned to it. Take a look at the following code

echo fileperms("test.txt");
?>

Out Put the above code is

33206

To get permissions in octal value

echo substr(sprintf("%o",fileperms("test.txt")),-4);
?>

Out Put the above code is

1777

Changing Permissions of a file

// Read and write for owner, nothing for everybody else
chmod("test.txt",0600);

// Read and write for owner, read for everybody else
chmod("test.txt",0644);

// Everything for owner, read and execute for everybody else
chmod("test.txt",0755);

// Everything for owner, read for owner's group
chmod("test.txt",0740);
?>

Labels: , ,

posted by adityachandra @ 9:26 AM, ,


Monday, June 2, 2008

Information about a file path in PHP

PHP has a wonderful function which tells us about the file path,extension and directory names. The function name is pathinfo(). Below is the code snippet. Give a try on your system

$path_parts = pathinfo('/www/htdocs/index.html');

echo $path_parts['dirname'], "\n"; //Output is /www/htdocs
echo
$path_parts['basename'], "\n"; //Output is index.html
echo $path_parts['extension'], "\n"; //Output is html
echo $path_parts['filename'], "\n"; // since PHP 5.2.0 //Output is index

?>

Labels: ,

posted by adityachandra @ 10:36 PM, ,