免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2058 | 回复: 6
打印 上一主题 下一主题

共享我的一些php程序代码和经验。 [复制链接]

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-12-02 09:11 |只看该作者 |倒序浏览
写程序有些年头了,发扬一下开源精神,欢迎大家批评指导。

Power by zyme

一、用大图制作小图函数。



  1. <?
  2. function get_picture_rebuild($src_pic_file, $dst_pic_file, $dst_pic_width, $dst_pic_height)
  3. {
  4.         // 自动制作小图片
  5.         $src_x = "0";        //源图起点x座标
  6.         $src_y = "0";        //源图起点y座标
  7.         $src_w = "0";        //源图终点w宽度
  8.         $src_h = "0";        //源图终点h高度
  9.         $dst_x = "0";        //目标图起点x座标
  10.         $dst_y = "0";        //目标图起点y座标
  11.         $dst_w = "0";        //目标图终点w宽度
  12.         $dst_h = "0";        //目标图终点h高度
  13.         list($src_w,$src_h,$type) = getimagesize($src_pic_file);
  14.         if($type == 1){$img_cf = imagecreatefromgif($src_pic_file);}
  15.         elseif($type == 2){$img_cf = imagecreatefromjpeg($src_pic_file);}
  16.         elseif($type == 3){$img_cf = imagecreatefrompng($src_pic_file);}
  17.         else{return false;}
  18.         if( ($src_w/$src_h)>;($dst_pic_width/$dst_pic_height) )
  19.         {
  20.                 $dst_w = $dst_pic_width;
  21.                 $dst_h = round($dst_pic_width * ($src_h/$src_w));
  22.         }
  23.         else
  24.         {
  25.                 $dst_w = round($dst_pic_height * ($src_w/$src_h));
  26.                 $dst_h = $dst_pic_height;
  27.         }
  28.         $img_ct = imagecreatetruecolor($dst_pic_width,$dst_pic_height);
  29.         $white  = imagecolorallocate($img_ct, 255, 255, 255);        //定义白色
  30.         imagefill($img_ct,1,1,$white);        //填充白色
  31.         imagecopyresampled($img_ct,$img_cf,round(($dst_pic_width-$dst_w)/2),round(($dst_pic_height-$dst_h)/2),0,0,$dst_w,$dst_h,$src_w,$src_h);
  32.         $argent  = imagecolorallocate($img_ct, 220, 220, 220);        //定义银色
  33.         imageline($img_ct,0,0,$dst_pic_width-1,0, $argent);        //画边框
  34.         imageline($img_ct,0,0,0,$dst_pic_height-1,$argent);        //画边框
  35.         imageline($img_ct,$dst_pic_width-1,0, $dst_pic_width-1,$dst_pic_height-1,$argent);        //画边框
  36.         imageline($img_ct,0,$dst_pic_height-1,$dst_pic_width-1,$dst_pic_height-1,$argent);        //画边框
  37.         imagejpeg($img_ct,$dst_pic_file);
  38.         imagedestroy($img_ct);
  39.         return $dst_pic_file;
  40. }
  41. ?>;
  42. <?
  43. //example
  44. $src_pic_file = "c:/老图片.jpg";
  45. $dst_pic_file = "c:/新图片.jpg";
  46. get_picture_rebuild($src_pic_file, $dst_pic_file, 150, 200);
  47. ?>;

复制代码

论坛徽章:
0
2 [报告]
发表于 2004-12-02 09:15 |只看该作者

共享我的一些php程序代码和经验。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2004-12-02 09:19 |只看该作者

共享我的一些php程序代码和经验。

二、安全的表单提交检查
经常遇到表单中的检查项,不想被强制检查到,就把网页下载下来,改了里面的javascript,再提交到服务器,骗了服务器(不好意思,我经常这样做)。怎么防止这样的手段?



  1. <?
  2. function get_post_self()
  3. {
  4.         // 检查是否为提交post给自己
  5.         if ( !$_POST ){ return false; }
  6.         $url_arr = parse_url($_SERVER["HTTP_REFERER"]);
  7.         if ( $url_arr['path']==$_SERVER['PHP_SELF'] ){ return true; }
  8.         if ( $url_arr['path']."index.php"==$_SERVER['PHP_SELF'] ){ return true; }
  9.         return false;
  10. }
  11. function get_get_legal($legal_referer)
  12. {
  13.         // 检查是否为合法的提交get 源
  14.         if ( !$_GET ){ return false; }
  15.         $url_arr = parse_url($_SERVER["HTTP_REFERER"]);
  16.         $self_dir = dirname($_SERVER['PHP_SELF']);
  17.         $real_arr = explode("/", "$self_dir/$legal_referer");
  18.         foreach( $real_arr as $one_dir )
  19.         {
  20.                 if($one_dir==".."){$the_url=dirname($the_url);continue;}
  21.                 if($one_dir=="."){continue;}
  22.                 $the_url = str_replace("\\","/","$the_url/$one_dir");
  23.                 $the_url = str_replace("//","/",$the_url);
  24.         }
  25.         if ( $url_arr['path']==$the_url ){ return true; }
  26.         if ( $url_arr['path']."index.php"==$the_url ){ return true; }
  27.         $tong_url = str_replace("\\","/","$self_dir/*");
  28.         $tong_url = str_replace("//","/",$tong_url);
  29.         if ( $the_url == $tong_url ){ return true; }
  30.         return false;
  31. }
  32. ?>;
  33. <?
  34. //example1
  35. if ( $sc->;get_post_self() )
  36. {
  37.         //something
  38. }
  39. //example2
  40. if ( $sc->;get_get_legal("./a.php") OR $sc->;get_get_legal("../b.php") )
  41. {
  42.         //something
  43. }
  44. ?>;

复制代码

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
4 [报告]
发表于 2004-12-02 09:21 |只看该作者

共享我的一些php程序代码和经验。

文件夹?~!
等我研究一下先.....

论坛徽章:
0
5 [报告]
发表于 2004-12-02 09:33 |只看该作者

共享我的一些php程序代码和经验。

精神可佳!!!1

论坛徽章:
0
6 [报告]
发表于 2004-12-02 15:28 |只看该作者

共享我的一些php程序代码和经验。

您写了多少年了?

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
7 [报告]
发表于 2004-12-03 10:48 |只看该作者

共享我的一些php程序代码和经验。

[quote]原帖由 "zyme"][/quote 发表:


1、检查上一页面的来源,轻而易举的阻挡你
2、使用验证码
3、使用Session
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP