2008/07/18
以我的生日为例,按照unix时间戳来算是19岁。
QQ空间上的估计也是这么判断的。


<?php
$day=28;
$month=12;
$year=1988;
$bdayunix=mktime(0,0,0,$month,$day,$year);
$nowunix=time();
$ageunix=$nowunix-$bdayunix;
$age=floor($ageunix/(365*24*60*60));
echo "您的年龄是:".$age."岁";
?>

Tags: ,
2008/07/12
加入干扰象素:

<?php    
/*    
* 文件:code.php    
* 作用:验证码生成    
*/    
$chinesechar = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z", "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
/*
$chinesechar = array("人","出","来","友","学","孝","仁","义","礼","廉","忠","国","中","易","白","者","火 ","土","金","木","雷","风","龙","虎","天","地", "生","晕","菜","鸟","田","三","百","钱","福 ","爱","情","兽","虫","鱼","九","网","新","度","哎","唉","啊","哦","仪","老","少","日","月 ","星");
*/
session_start();
// 设置 content-type    
header("Content-type: image/png");
// 创建图片    
$im = imagecreatetruecolor(62,20);
// 创建颜色    
$fontcolor = imagecolorallocate($im,0,0,0);  
$bgcolor=imagecolorallocate($im,200,200,200);
imagefill($im,0,0,$bgcolor);
// 设置文字    

for($i=0;$i<4;$i++)
{
$text.=$chinesechar[(array_rand($chinesechar))];    
}
$_SESSION['code'] = $text;
// 设置字体
$font = 'cc.ttf';

// 添加文字    
imagettftext($im,12,0,3,15,$fontcolor,$font,$text);
srand((double)microtime()*1000000);
for($i=0;$i<200;$i++)   //加入干扰象素
{
    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
    imagesetpixel($im,rand()%70,rand()%30,$randcolor);
}
// 输出图片    
imagepng($im);    
imagedestroy($im);    
?>


中文验证码好像不能输出?暂时没有试成功,不知道怎么编写,还有一个问题是如何绘制一个矩形边框?如果矩形边框要为黑色?程序又如何编写?高手跟帖。
Tags: ,
2007/11/06
orderform.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Bob's basic order form</title>
</head>
<body>
<form action="processorder.php" method="post">
<table>
<tr bgcolor="#CCCCCC">
<td width="150">Item</td>
<td width="15">Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align="center"><input type="text" name="tireqty" size="3" maxlength="3" /></td>
</tr>
<tr>
<td>Oil</td>
<td align="center"><input type="text" name="oilqty" size="3" maxlength="3"/></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align="center"><input type="text" name="sparkqty" size="3"
maxlength="3"/></td>
</tr>
<tr>
<td>Address</td>
<td align="center"><input type="text" name="address" size="20" ></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="提交"/></td>
</tr>
</table>
</form>
</body>
</html>



processorder.php



<?php
$tireqty=$_POST['tireqty'];
$oilqty=$_POST['oilqty'];
$sparkqty=$_POST['sparkqty'];
$address=$_POST['address'];

$document_root=$_SERVER['DOCUMENT_ROOT'];
?>
<html>
<head>
<title>
Bob's Auto Parts-Order Results
</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<?php
$date=date('H:i,jS F');
echo '<p>Order processed at';
echo $date;
echo '</P>';
echo '<P>Your order is as follows:</P>';

$totalqty=0;
$totalqty=$tireqty+$oilqty+$sparkqty;
echo 'Items ordered: '.$totalqty.'<br>';

if($totalqty==0)
{
echo 'You did not order anything on the previous page!<br>';
}
else
{
if($tireqty>0)
  echo $tireqty.'tires<br>';

if($oilqty>0)
  echo $oilqty.'oil<br>';

if($sparkqty>0)
  echo $sparkqty.'spark<br>';
}


$totalamount=0.00;

define('tireprice',100);
define('oilprice',10);
define('sparkprice',4);

$totalamount=$tireqty*tireprice+$oilqty*oilprice+$sparkqty*sparkprice;

$totalamount=number_format($totalamount, 2, '.', ' ');
echo '<p>Total of order is '.$totalamount.'</p>';
echo '<p>Address to ship to is '.$address.'</P>';

$outputstring=$date."\t".$tireqty."tires \t".$oilqty."oil \t".$sparkqty."spark plugs\t\$".$totalamount."\t".$address."\n";

@ $fp=fopen("$document_root/order/data/order.txt",'ab');
if(!$fp)
{
    echo '<P><strong>Your order could not be processed at this time.'
    .'Please try again later.</strong></P></body></html>';
 
  exit;
 
}


fwrite($fp,$outputstring,strlen($outputstring));
fclose($fp);

echo '<P>Order Written.</P>';

?>
</body>
</html>



测试页面 http://www.waigua.biz/order/orderform.html
Tags:
2007/07/15
PHP官方今天在网站上发布公告,中止PHP4版本的开发。

声明中认为,PHP5从发布到现在已有整整三年时间,经过时间的考验,PHP5已十分成熟稳定并且高效。同时为PHP6的发布作准备。PHP4的支持将于年底中止。

从2007年12月31日起,PHP4将不会再推出新版本,但仍然会修补重大BUG直到2008年8月8日。

所以,呼吁用户,在今年余下的时间里。尽快的适应PHP5,并及时将老代码移植到PHP5或者更新的版本中来。以享受PHP的高效和完善的技术支持。
Tags: , , , ,
Theme by Marshal. Powered by Bo-Blog 2.1.1 ReleaseCode detection by Bug.Center.Team