[备忘]PHP简单调试(1 位领导批示)

还是很方便的调试方式..记录一下备忘

1
2
ini_set("error_log", "E:\php_error.log");  
error_log($output,0);

php生成渐变图片(0 位领导批示)

问题链接:http://bbs.blueidea.com/thread-2957105-1-1.html

我是使用GD的 imagefilledrectangle 函数来实现的. 不知是否有更好的解法

1
2
3
4
5
6
7
8
9
10
11
12
<?php
$im = imagecreate(255, 255);
$bg = imagecolorallocate($im, 0, 0, 0);
for($i=255; $i>=0; $i--)
{
    $color = imagecolorallocate($im, $i, $i, $i);
    imagefilledrectangle($im, 0, $i, 255, 1, $color);
}
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
Tags : , , ,

PHP处理简单图片的颜色填充(0 位领导批示)

原问题地址: http://bbs.blueidea.com/viewthread.php?tid=2956421


现在有一张背景色为纯蓝色(或者红色等) 并且与照片里人物有很明显的反差色彩 的一寸单人照照片,现想把,该图片中的蓝色背景用PHP处理为白色。即类似于PS中,用白色填充蓝色的效果。

使用GD库的imagecolorset函数可以修改简单的索引色. 不过只能对gif与png图片有效

1
2
3
4
5
6
7
8
<?php
$img = file_get_contents('http://home.blueidea.com/attachment/200911/9/207382_1257738485WdvH.gif');
$im = imagecreatefromstring($img);
$bg = imagecolorat($im, 0, 0);
imagecolorset($im, $bg, 0, 0, 255);
imagepng($im);
imagedestroy($im);
?>

[备忘]PHP无法加载LDAP扩展的解决方法(2 位领导批示)

最近的项目中需要使用域账号访问域控服务器. 要开启PHP的LDAP扩展.

打开php.ini后去掉 ;extension=php_ldap.dll 的分页.重启APACHE.
刷新页面..显示 Call to undefined function ldap_connect()

0_o 咋回事捏? 打开PHPINFO发现没有 LDAP.. 说明木有加载上..

最终找到解决方法:


将PHP目录下的libeay32.dll和ssleay32.dll拷贝到system32目录下.重启APACHE

搞电.. (^_^)

PHP创建文件重名.重新命名文件算法(0 位领导批示)

原问题: http://bbs.blueidea.com/thread-2942989-1-1.html

随便写了一个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
function createFile($filename, $content = '')
{
    $fp = file_put_contents($filename, $content);
}
 
// 要创建的文件名称
$filename = 'www.txt';
 
if(file_exists($filename))
{
    // 打开当前目录
   $handle = opendir('./');
    $fileinfo = pathinfo($filename);
    //print_r($fileinfo);
    $files = array();
    while (false !== ($file = readdir($handle)))
    {
        if(preg_match_all("/{$fileinfo['filename']}(\d*)\.{$fileinfo['extension']}/i", $file, $match))
        {
            $max = max($match[1]);
            if($max)
            {
                $createfile = $fileinfo['filename'] . ($max + 1) . '.' . $fileinfo['extension'];
            }
            else
            {
                $createfile = $fileinfo['filename'] . '1.' . $fileinfo['extension'];
            }
        }
    }
    createFile($createfile);
}
else
{
    createFile($filename);
}
?>

另一种思路..使用临时文件作记数器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function createFile($filename, $content = '')
{
    if(file_exists($filename . '.tmp'))
    {
        $num = (int) file_get_contents($filename . '.tmp') + 1;
        $fileinfo = pathinfo($filename);
        file_put_contents($fileinfo['filename'] . '(' . $num . ')' .$fileinfo['extension'], $content);
        file_put_contents($filename . '.tmp', $num);
    }
    else
    {
        file_put_contents($filename, $content);
        file_put_contents($filename . '.tmp', 1);
    }
}
createFile('test.txt');
?>

[转]PHP 5.3中的命名空间使用方法浅述(1 位领导批示)

PHP 5.3 的一个新的重要特性就是 命名空间(namespace)。
这一特性在 PHP5.0x 时候就提出过,后来被取消并安排在 PHP6 中实现。而此次又再次“提前”到了 PHP 5.3 发布,可见开发人员对其的重视以及谨慎的态度。

官方发布时说明文档的内容可能已过期(documentation maybe out dated),所以在这里简单的说明命名空间的用法:首先是声明一个命名空间,加入了新的关键字 namespace ,其应在类文件的开头

全文阅读 »

[备忘]Portable PHP password hashing framework(0 位领导批示)

WordPress 采用的密码加密算法..记录备忘

主要有两个方法:
1.HashPassword 加密密码
2.CheckPassword 进行密码验证

全文阅读 »

Tags : , ,

Discuz的passport与Perl版本的passpost[通用](1 位领导批示)

最近做的一个项目中 需要perl与php进行数据通信.我用LWP::UserAgent的POST方法实现了与PHP程序的连接.
不过在安全上有很大问题.找了找.DZ的passport就直接拿来用了..哇卡卡..

首先是Discuz的passport方法

全文阅读 »

PHP debug三个常用方法(备忘)(0 位领导批示)

一.ReflectionFunction

能打印出一个函数信息

使用方法:

1
2
3
4
function silver() {
    echo 'silver';
}
Reflection::export(new ReflectionFunction('silver'));

 

二.get_defined_functions

这个函数返回一个数组..数组中包含所有已经定义的函数(包括PHP内部函数,所以要慎用).

全文阅读 »

setcookie函数的作用域问题(0 位领导批示)

在不同目录下的文件.不能访问各自设置的cookie

查了一下手册.setcookie函数有一个path参数.可以设置本地cookie的作用域

解释如下:

The path on the server in which the cookie will be available on. If set to ‘/’, the cookie will be available within the entire domain . If set to ‘/foo/’, the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

另一个参数domain
则是设置网络上cookie的作用域.

解释如下:

The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you’d set it to ‘.example.com’. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain. Refer to tail matching in the » spec for details.

示例:

  1. $setcookday = 30;//设置cookie有效期
  2. setcookie('uname', '银子', time() + ($setcookday * 24 * 60 * 60),'/','qqdang.net'); //分别为cookie名称.cookie值.cookie有效时间.cookie本地作用域.cookie网络作用域

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志