Chinaunix
标题:
共享我的一些php程序代码和经验。
[打印本页]
作者:
zyme
时间:
2004-12-02 09:11
标题:
共享我的一些php程序代码和经验。
写程序有些年头了,发扬一下开源精神,欢迎大家批评指导。
Power by zyme
一、用大图制作小图函数。
<?
function get_picture_rebuild($src_pic_file, $dst_pic_file, $dst_pic_width, $dst_pic_height)
{
// 自动制作小图片
$src_x = "0"; //源图起点x座标
$src_y = "0"; //源图起点y座标
$src_w = "0"; //源图终点w宽度
$src_h = "0"; //源图终点h高度
$dst_x = "0"; //目标图起点x座标
$dst_y = "0"; //目标图起点y座标
$dst_w = "0"; //目标图终点w宽度
$dst_h = "0"; //目标图终点h高度
list($src_w,$src_h,$type) = getimagesize($src_pic_file);
if($type == 1){$img_cf = imagecreatefromgif($src_pic_file);}
elseif($type == 2){$img_cf = imagecreatefromjpeg($src_pic_file);}
elseif($type == 3){$img_cf = imagecreatefrompng($src_pic_file);}
else{return false;}
if( ($src_w/$src_h)>;($dst_pic_width/$dst_pic_height) )
{
$dst_w = $dst_pic_width;
$dst_h = round($dst_pic_width * ($src_h/$src_w));
}
else
{
$dst_w = round($dst_pic_height * ($src_w/$src_h));
$dst_h = $dst_pic_height;
}
$img_ct = imagecreatetruecolor($dst_pic_width,$dst_pic_height);
$white = imagecolorallocate($img_ct, 255, 255, 255); //定义白色
imagefill($img_ct,1,1,$white); //填充白色
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);
$argent = imagecolorallocate($img_ct, 220, 220, 220); //定义银色
imageline($img_ct,0,0,$dst_pic_width-1,0, $argent); //画边框
imageline($img_ct,0,0,0,$dst_pic_height-1,$argent); //画边框
imageline($img_ct,$dst_pic_width-1,0, $dst_pic_width-1,$dst_pic_height-1,$argent); //画边框
imageline($img_ct,0,$dst_pic_height-1,$dst_pic_width-1,$dst_pic_height-1,$argent); //画边框
imagejpeg($img_ct,$dst_pic_file);
imagedestroy($img_ct);
return $dst_pic_file;
}
?>;
<?
//example
$src_pic_file = "c:/老图片.jpg";
$dst_pic_file = "c:/新图片.jpg";
get_picture_rebuild($src_pic_file, $dst_pic_file, 150, 200);
?>;
复制代码
作者:
reffo
时间:
2004-12-02 09:15
标题:
共享我的一些php程序代码和经验。
作者:
zyme
时间:
2004-12-02 09:19
标题:
共享我的一些php程序代码和经验。
二、安全的表单提交检查
经常遇到表单中的检查项,不想被强制检查到,就把网页下载下来,改了里面的javascript,再提交到服务器,骗了服务器(不好意思,我经常这样做)。怎么防止这样的手段?
<?
function get_post_self()
{
// 检查是否为提交post给自己
if ( !$_POST ){ return false; }
$url_arr = parse_url($_SERVER["HTTP_REFERER"]);
if ( $url_arr['path']==$_SERVER['PHP_SELF'] ){ return true; }
if ( $url_arr['path']."index.php"==$_SERVER['PHP_SELF'] ){ return true; }
return false;
}
function get_get_legal($legal_referer)
{
// 检查是否为合法的提交get 源
if ( !$_GET ){ return false; }
$url_arr = parse_url($_SERVER["HTTP_REFERER"]);
$self_dir = dirname($_SERVER['PHP_SELF']);
$real_arr = explode("/", "$self_dir/$legal_referer");
foreach( $real_arr as $one_dir )
{
if($one_dir==".."){$the_url=dirname($the_url);continue;}
if($one_dir=="."){continue;}
$the_url = str_replace("\\","/","$the_url/$one_dir");
$the_url = str_replace("//","/",$the_url);
}
if ( $url_arr['path']==$the_url ){ return true; }
if ( $url_arr['path']."index.php"==$the_url ){ return true; }
$tong_url = str_replace("\\","/","$self_dir/*");
$tong_url = str_replace("//","/",$tong_url);
if ( $the_url == $tong_url ){ return true; }
return false;
}
?>;
<?
//example1
if ( $sc->;get_post_self() )
{
//something
}
//example2
if ( $sc->;get_get_legal("./a.php") OR $sc->;get_get_legal("../b.php") )
{
//something
}
?>;
复制代码
作者:
zyme
时间:
2004-12-02 09:21
标题:
共享我的一些php程序代码和经验。
文件夹?~!
等我研究一下先.....
作者:
aspbiz
时间:
2004-12-02 09:33
标题:
共享我的一些php程序代码和经验。
精神可佳!!!1
作者:
redor
时间:
2004-12-02 15:28
标题:
共享我的一些php程序代码和经验。
您写了多少年了?
作者:
HonestQiao
时间:
2004-12-03 10:48
标题:
共享我的一些php程序代码和经验。
[quote]
原帖由 "zyme"][/quote 发表:
1、检查上一页面的来源,轻而易举的阻挡你
2、使用验证码
3、使用Session
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2