支持!N久没写PHP,手头也没什么好东东,~_~

解决方案 »

  1.   

    我通常把一些每个页面比较常用到的都独立成一个文件,比如:一个通用的数据操作类
    一个session验证程序等。然后在需要的页面include进去,这样的并不算上面技巧吧
    不过一般来说我的整站程序所作的数据库操作都是用一个类来作的,无论是数据库连接、查询、更新等
      

  2.   

    我改编的月历函数:
    <?/*
    月历函数
    array calendar(year,month)
    输出周期为星期一到星期天(not sunday to saturday)
    如果1号是星期n(n>1),则数组前面空出n-1个位置
    */
    function calendar($year,$month,$style="world"){ if(empty($year)){$year=date('Y',time());}
    if(empty($month)){$month=date('m',time());} $return = array(); #重新设定一些变量
    $date=01; #当月的天数
    $day=01; #循环中的日 #算出当月的天数
    while (checkdate($month,$date,$year)){
    $date++;
    } $no=date('w', mktime(0,0,0,$month,$day,$year));
    if ($no == 0){
    $no=7;
    }
    if($style == "world"){
    $no=$no-1;
    }
    else{
    $no=$no-2;
    } for($i=0;$i<=$no;$i++){
    $return[$i]="";
    } for($i=1;$i<$date;$i++){
    $return[$i+$no]=$i;
    } return $return;}#end function calendar?>
      

  3.   

    我写的生成随机字符的函数:/*随机字符串生成
    调用格式:
    $password = rndstr(10,int type); 
    生成一个10位的随机密码
    */
    function rndstr($length,$type=0) { 
    $hash = '';
    switch($type){
    case 0:$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';break;
    case 1:$chars = '0123456789';break;
    case 2:$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';break;
    case 3:$chars = 'abcdefghijklmnopqrstuvwxyz';break;
    case 4:$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';break;
    case 5:$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';break;
    case 6:$chars = '0123456789abcdefghijklmnopqrstuvwxyz';break;
    case 7:$chars = 'ABCEFGHJKLMNTWXYZ2346789';break;
    default:$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';break;
    }

    $max = strlen($chars) - 1;
    mt_srand((double)microtime() * 1000000);
    for($i = 0; $i < $length; $i++) { 
    $hash .= $chars[mt_rand(0, $max)]; 

    return $hash; 
    }#end function rndstr
      

  4.   

    <?
    /*
    生成4位的验证码图片
    需要结合rndstr函数(string.func.php)
    使用说明:直接调用imgauth(string authcode)
    */
    function imgauth($authcode="ERR!"){
    Header("Content-type: image/PNG"); 
    srand((double)microtime()*1000000);
    $im = imagecreate(45,20); $black=ImageColorAllocate($im, 0,0,0); $backgnd=array(
    1=>ImageColorAllocate($im, 230,230,0),
    2=>ImageColorAllocate($im, 230,230,230),
    3=>ImageColorAllocate($im, 0,230,230),
    4=>ImageColorAllocate($im, 250,150,250),
    );
    $background=$backgnd[rand(1,4)];
    imagefill($im,0,0,$background);
    imagestring($im, 5, 4, 3, $authcode, $black);  for($i=0;$i<100;$i++){
    imagesetpixel($im, rand()%70 , rand()%30 , $background);
    } ImagePNG($im);
    ImageDestroy($im);
    }#end function imgauth
    ?>
    以上函数需要结合我上面的生成随机字符串的函数
    这样就可以实现验证码的生成建立auth.php:
    <?
    include "func.string.php";
    include "func.image.php";$authcode=rndstr(4,7); #注意,type设定为7,因为用来显示的字母必须没有异议,比如1和I就不行
    imgauth($authcode);
    ?>然后在其它页面调用<img src="auth.php">对于验证码的保存,可以使用SESSION或者COOKIE或者数据库存储
      

  5.   

    俺的文件上传ftp的:
    <?php $ftp_server="ftp服务器(最好用IP)"; 
    $ftp_username="ftp用户名"; 
    $ftp_password="登录密码"; 
    $ftp_dir="目录(如设置为 /)"; if ($action == "OK") 

    $con = ftp_connect($ftp_server); //连接ftp
    ftp_login($con, $ftp_username, $ftp_password); //用户登录
    $suss=$con;
    ftp_chdir($suss, $ftp_dir); //cd到指定目录$ok_code = ftp_put($suss, $upload_file_name, $upload_file, FTP_BINARY); //put文件 if ($ok_code == 1) 

    echo "文件上传成功!\n"; 

    else 

    echo "文件上传失败!\n"; 

    ftp_quit($suss); // 关闭ftp连接
    } ?>
      

  6.   

    很好!!谢谢大家!!!!study!!
      

  7.   

    GD显示中文的时候就用的到了//***********************************************************
    //
    //下面这两个函数是将汉字由 Gb2 转化成 Utf8 格式
    //
    //调用方式是:string gb2utf(string source);
    //
    //
    //
    //***********************************************************function gb2utf($str)
    {
    global $MB,$VdpSystemRoot; if($MB==""){
    $filename = "$VdpSystemRoot"."include/html.txt";
    $fd = fopen ($filename, "r");
    $MB = fread ($fd, filesize ($filename));
    fclose ($fd);
    }
    $string="";
    $a=0;
    $b=strlen($str);
    while($a<$b){
    if(ord($str[$a])>128){
    //高位偏移量
    $c=(ord($str[$a])-161)*94;
    $a++;
    //低位偏移量
    $c=$c+ord($str[$a])-161;
    $c=$c*5;
    if(bin2hex(substr($MB,$c+2,1))==0x20){
    $string.=substr($MB,$c,2);
    }else{
    $string.=substr($MB,$c,3);
    }
    $tem=bin2hex($string);
    $a++;
    }else{
    $string.=$str[$a];
    $a++;
    }
    }
    return $string;
    }
      

  8.   

    header();
    setcookie();
    俩函数之前必须没输出及htm代码
      

  9.   

    html.txt 太长了,如果谁确实需要,到时候给我发邮件就可以了[email protected]
      

  10.   

    连接数据库最好用类封装
    代码在http://www.phpe.com上有