Monday, June 29, 2009

convert DATE format to UNIX TIMESTAMP in mysql


Table : info
============================
id name dob
============================
1 test1 2008-12-03 00:00:00
2 test2 2009-06-01 00:00:00
============================

$sql = "SELECT UNIX_TIMESTAMP(dob) AS birthdate FROM info WHERE 1=1";

OUTPUT :
-------------
birthdate
========
1228280400
1243828800

How to convert UNIX TIMESTAMP to DATE in mysql


Table : info
============================
id name dob
============================
1 test1 1235994659
2 test2 1235994707
============================


$sql = "SELECT DATE(FROM_UNIXTIME(dob)) AS birthdate FROM info WHERE 1=1";


OUTPUT :
-------------
birthdate
========
2009-03-02
2009-03-02

Monday, June 22, 2009

fopen fwrite in php

// Create ip.txt file
// place code below

$iptxt = $_SERVER['REMOTE_ADDR']
$fname = "ip.txt";
$fhandle = fopen($fname,"r");
$fhandle = fopen($fname,"w");
fwrite($fhandle,$iptxt);
fclose($fhandle);

Friday, June 19, 2009

how to check all checkboxes within a div elemen in javascript

JAVASCRIPT
=======================================
<script type="text/javascript">
function checkByParent(aId, aChecked) {
var collection = document.getElementById(aId).getElementsByTagName('INPUT');
for (var x=0; x if (collection[x].type.toUpperCase()=='CHECKBOX')
collection[x].checked = aChecked;
}
}
</script>
<a href="#" onclick="checkByParent('mydiv', true)">CHECK</a>
<div id="mydiv">
CHECK 1 <input type="checkbox">
CHECK 2 <input type="checkbox">
CHECK 3 <input type="checkbox">
CHECK 4 <input type="checkbox">
CHECK 5 <input type="checkbox">
</div>

Tuesday, June 16, 2009

The reference to entity must end with the ';' delimiter

// For Blogger post if u got above error please try below code
// this will post html content in a publish post
$DB_ARTICLE[article_title]="Any Title";
$DB_ARTICLE[article_text] = <h1>Your content</h1>"
$entry = "<entry xmlns='http://www.w3.org/2005/Atom'>
<title type='text'>".$DB_ARTICLE[article_title]."</title>
<content type='text/html'>".htmlentities($DB_ARTICLE[article_text])."</content>
</entry>";

Thursday, June 11, 2009

how to create login logout script in php

I search through the internet and find below usefull tutorial
check out this is very easy step by step script provided
with graphical view too.

PHP Login script tutorial

how to create rss feed in php

// How to create RSS feed for site in php
// Check your rss is correct or not @ http://validator.w3.org/feed/


$a='<?xml version="1.0" encoding="UTF-8"?>';
$a .='<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$a.='<channel>';
$a.= '<atom:link href="http://www.anydomain.com?feed=xml" rel="self" type="application/rss+xml" />';
$a.='<title>Your Site Title</title>';
$a.='<link>http://www.yourdomain.com</link>';
$a.='<description>Your site Details here</description>';
$a.='<language>en-us</language>';
$a.='<docs>http://blogs.law.harvard.edu/tech/rss/</docs>';
$a.='<item>';
$a.='<title>Title For Item1</title>';
$a.='<link>http://www.linktoitem1.com</link>';
$a.='<guid>http://www.linktoitem1.com</guid>';
$a.='<description>Item1 Description Here</description>';
$a.='<pubDate>'.date("D, d M Y H:i:s T",UNIX_TIMESTAMP).'</pubDate>';
$a.='</item>';
$a.='<item>';
$a.='<title>Title For Item2</title>';
$a.='<link>http://www.linktoitem2.com</link>';
$a.='<guid>http://www.linktoitem2.com</guid>';
$a.='<description>Item2 Description Here</description>';
$a.='<pubDate>'.date("D, d M Y H:i:s T",UNIX_TIMESTAMP).'</pubDate>';
$a.='</item>';
$a.='</channel>';
$a.='</rss>';

echo trim($a);

How to swap 2 variable values without using 3rd variable in php

$a = 10;
$b = 20;

$a=$a+$b;
$b=$a-$b;
$a=$a-$b;

echo $a;
echo $b;

Wednesday, June 10, 2009

how to order mysql query via input order in an IN() clause

SELECT *
FROM `articles`
WHERE article_id
IN ( 31, 27, 36, 23 )
ORDER BY FIND_IN_SET(
article_id,'31,27,36,23' )
LIMIT 0 , 30

Monday, June 8, 2009

Free sandbox paypal script in php

// First create 3 files in root of site called
// paypal_return.php,cancel_return.php,notify_return.php
// Replace business@domain.com with your test business account email id

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" name="frm" id="frm" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="business@domain.com">
<input type="hidden" name="item_name" value="Deposite Balance">
<input type="hidden" name="amount" value="100">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="charset" value="utf-8">
<input type="hidden" name="rm" value="2" >
<input type="hidden" name="return" id="return" value="http://yoursite/paypal_return.php" />
<input type="hidden" name="cancel_return" value="http://yoursite/cancel_return.php">
<input type="hidden" name="notify_url" value="http://yoursite/notify_return.php">
<input type="hidden" name="first_name" value="Vasim" />
<input type="hidden" name="last_name" value="Padhiyar" />
<input type="submit" value="Paypal" name="btn" />
</form>

// After Payment Complete , Paypal will return you Token in request
// on paypal_return.php
//Check This Token Transation Record on paypal server as below

$order_status = check_paypal($_REQUEST['tx']);

if($order_status=='SUCCESS')
{
// Update Database and return to main page
}
else
{
// Error msg
}


// Replace $auth_token with your appropriate token
function check_paypal($paypal_tx)
{
$status = "FAIL";

$req = 'cmd=_notify-synch';

$tx_token = $paypal_tx;

$auth_token = "03suYLK9KVmKHZMETOKW4Ad0g2uDM7R2mS0-IUd4B2tFr6E0SlDZRUVSX-G";

$req .= "&tx=$tx_token&at=$auth_token";

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

if (!$fp)
{
$status = "FAIL";
}
else
{
fputs ($fp, $header . $req);

$res = '';
$headerdone = false;
while (!feof($fp))
{
$line = fgets ($fp, 1024);

if (strcmp($line, "\r\n") == 0)
{
$headerdone = true;
}
else if ($headerdone)
{
$res .= $line;
}
}

$lines = explode("\n", $res);

$keyarray = array();

if (strcmp ($lines[0], "SUCCESS") == 0)
{
$status = "SUCCESS";
}
else if (strcmp ($lines[0], "FAIL") == 0)
{
$status = "FAIL";

}

}

fclose ($fp);

return $status;
}

How to setup a SMTP authentication in php

Send email using PHP SMTP mail Pear functions

//How to set SMTP authentication in php
// Mail.php is located in /usr/share/pear/ directory.
// you can install it from http://pear.php.net/package/Mail

Sample source code

echo send_mail($to,$subject,$body); // return true/false

function send_mail($to,$subject,$body)
{

require_once "Mail.php";

$from = "admin@domain.com";
$host = "mail.domain.com";
$port = "25";
$username = "usernam";
$password = "password";

$headers = array ('From' => $from,
'To' => $to,
'Reply-To' => $from,
'Return-Path' => $from,
'Message-ID' => time()."-".$from,
'Subject' => $subject,
'MIME-Version' => '1.0',
'Content-type' => 'text/html',
'X-Mailer' => 'PHP v'.phpversion(),
'Date' => date("r"));

$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail))
{
$output = false;
}
else
{
$output = true;
}

return $output;
}

Friday, June 5, 2009

how to use if condition with ? and : in php script

// This example also checks the url is with http:// or not

$flag_url = checkURL_ForHTTP($_POST['siteurl']);

$siteurl = ($flag_url==true) ? $_POST['siteurl'] : "http://".$_POST['siteurl'];

function checkURL_ForHTTP($raw_url)
{
if(substr($raw_url,0,7)!="http://")
{
return false;
}
else
{
return true;
}
}

How to convert From Number to Euro in php

function NumberToEuro($num)
{
$count=0;
$start = -3;
$rem=strlen($num)%3;
$rem=strlen($num)-$rem;
for($i=0; $i<=strlen($num); $i=$i+3)
{
if($i==$rem)
{ $len=strlen($num)%3; } else { $len = 3; }
$array[$count] = $array[$count].substr($num,$start,$len).".";
$count++;
$start=$start - 3;
}
for($i=count($array)-1; $i>=0; $i--)
{
$str = $str . $array[$i];
}
return $str;
}

How to put FCKeditor in php

Just Follow the steps below

1. Download FCKeditor_2.6.3.zip and compress it.
2. You will get FCKeditor_2.6.3 folder, rename it to FCKeditor and put in root of your site.
3. include file by using : include("FCKeditor/fckeditor.php") ;
4. specify path of FCKeditor folder : $editor_path = "FCKeditor/";
5. To Display editor put following codes
$oFCKeditor = new FCKeditor('description') ;
$oFCKeditor->BasePath = 'FCKeditor/' ;
$oFCKeditor->Width = 550 ;
$oFCKeditor->Height = 280 ;
$oFCKeditor->Value = $description;
$oFCKeditor->Create() ;
6. Now you can get the value of FCKeditor as POST/GET as $_REQUEST['description']
7. finish.

how to format text of textarea in paragraph

// use nl2br() function

// example
//How to format the text inside of textarea box
$string = "This is Demo.
This is new line.
This is another line. ";

echo nl2br($string);

how to use captcha

CAPTCHA


stands for "Completely Automated Public Turing test to tell Computers and Humans Apart".


Requirments


The library requires PHP 4 compiled with GD 1 or 2 (Image Generation) and FreeType text support. It should work fine with Linux, Mac OS X or Windows based systems although you will need to change the default temporary file storage directory specified when using with Windows. PHP session support is also required. The audio CAPTCHA requires the Flite text to speech synthesis engine - more details on set up below.


Download Now















Thursday, June 4, 2009

how to use like keyword in mysql

SELECT
*
FROM
yourtable
WHERE
id LIKE
'%keyword%'
OR position LIKE
'%keyword%'
OR category LIKE
'%keyword%'
OR location LIKE
'%keyword%'
OR description LIKE
'%keyword%'
OR refno LIKE
'%keyword%';

POST vs GET

Get Method
[1] Get method display all the paremeter in Browser URL that you pass in form.
[2] It also display hidden variable in URL. no security of hidden variable.
[3] you can pass Limited number of paremeter in url

Post Method
[1] Post Method does not display any parameter in URL
[2] Hidden variable will remain hidden.

How to get meta information from page url in php

// php provides following function to extract meta tag

$array = get_meta_tags("http://scriptforphp.blogspot.com");


print_r($array);

Tuesday, June 2, 2009

Free article spinner script

// This is Only Demo Script, To get Full Script Contact me : iamvasim@gmail.com

$string = "The {Banana|Apple} is {Good|Best} for all {boys|girls|man|woman|child}.";

$start_pos = strpos($string,'{');

$end_pos = strpos($string,'}');


$position = strposall($string,"{");


for($i=0; $i<($position); $i++)
{

$start = $position[$i];

$end = strpos($string,'}',$start);

$spin_string[] = trim(substr($string,$start,($end-$start)+1));

}


for($i=0; $i<count($spin_string); $i++)
{

$temp = $spin_string[$i];

$temp = remove_first($temp);

$temp = remove_last($temp);

$explode[$i] = explode('|',$temp);

}

// PLEASE CONTACT ME TO GET REST OF CODE

// Output

print_r(
$spin_string);
Array
(
[0] => {Banana|Apple}
[1] => {Good|Best}
[2] => {boys|girls|man|woman|child}
)

print_r($explode);

Array
(
[0] => Array
(
[0] => Banana
[1] => Apple
)

[1] => Array
(
[0] => Good
[1] => Best
)

[2] => Array
(
[0] => boys
[1] => girls
[2] => man
[3] => woman
[4] => child
)

)

// AND THE FINAL ARRAY WILL HAVE FOLLOWING
Array
(
[0] => The Banana is Good for all boys.
[1] => The Banana is Good for all girls.
[2] => The Banana is Good for all man.
[3] => The Banana is Good for all woman.
[4] => The Banana is Good for all child.
[5] => The Banana is Best for all boys.
[6] => The Banana is Best for all girls.
[7] => The Banana is Best for all man.
[8] => The Banana is Best for all woman.
[9] => The Banana is Best for all child.
[10] => The Apple is Good for all boys.
[11] => The Apple is Good for all girls.
[12] => The Apple is Good for all man.
[13] => The Apple is Good for all woman.
[14] => The Apple is Good for all child.
[15] => The Apple is Best for all boys.
[16] => The Apple is Best for all girls.
[17] => The Apple is Best for all man.
[18] => The Apple is Best for all woman.
[19] => The Apple is Best for all child.
)