PHP中数据有效性验证

作者 : admin 于 2008年06月14日, 20:54:57
2008
06-14

在php的开发过程中,我们的error_reporting()开到最严格,2047,因此,好多php本身可避免的报错也都会出来,就跟C一样让在在强类型状态下工作。

为了尽量使程序兼容,我们对每个变量的有效性进行严格判断。

我一般使用 isset($a) ? $a : ”;这种方式对变量进行判断,如果变量不存在的话初始化变量。

当然在其他的地方也可以使用该方法检验变量有效性。

底下是大部分进行验证的函数。

检测变量状态: isset()   empty()

检测变量类型 is_array() is_double() is_float() is_real()  is_long() is_int() is_integer() is_string() is_object()

具体使用可以查下手册

PHP并不比C或者其他语言差,关键在于你编程的态度.

centos5安装指南(简单篇)

作者 : admin 于 2008年06月13日, 21:50:17
2008
06-13

进入默认页面,直接回车即可

测试光盘文件的完整性,我一般都跳过

阅读全部 »

混过一天是一天

作者 : admin 于 2008年06月05日, 08:55:48
2008
06-5

又一天了,烦恼的上班下班,自行车冲锋!总是想起一个电影名字《冲出亚马逊》,而我每天是冲出清河镇。

家里不能上网,好久没学习,昨天看了看分词,除了二分法和词库分词法,也没看出点什么。

收了两个徒弟,教他们PHP,一直也没时间。

网通办事效率有点太低了,BS我们大班长!

上网后拼命学习!

PHP Shell初体验

作者 : admin 于 2008年05月25日, 16:59:51
2008
05-25

在linux(centos5)上编译安装 php-5.2.6.tar.gz ,configure参数一定要带上 –enable-cli

完成后,php所在目录 /usr/local/bin/php

运营 ./php -v 显示php版本信息,证明安装成功

编写我的第一个php shell脚本
#!/usr/local/bin/php -q
echo “Hello World!”;
?>

保存为 test.sh
运行,屏幕会 回显 Hello World!

在命令行下,不会存在get post之类的动作,除非参数写到页面内,而php恰巧提供了这样的命令行参数接口,$argv
修改test.sh
#!/usr/local/bin/php -q
print_r($argv);
?>

加参数运行 ./test.sh t1 t2 ,回显为

Array
(
[0] => ./test.sh
[1] => t1
[2] => t2
)

PHP SHELL,用php来代替bash

作者 : admin 于 2008年05月24日, 23:50:51
2008
05-24

总看到招聘php程序员的帖子说要求php程序员熟练运用linux,shell,我估计熟悉LAMP配置,在这个架构下开发php的人不在少数,但说到SHELL,估计有一批人一冒一身的冷汗。
c shell,bash shell的确用的少,但php shell你说不懂,就该左右开弓一百八十个大嘴巴。
php本身就是一种shell,在php4之后,php编译有个 –enable-cli 参数,php5之后这个参数几乎成了标配参数。php一样可以作为shell脚本运行在装有php环境的服务器上。
而在phpchina.com phpx.com总多bbs的招聘上,居然没有哪个php程序员拿出php shell这个技能去跟他们交涉。而实际上,phpshell的功能根本不比bash弱,而且在LAMP环境中,php shell比bashshell有诸多的优点。

下边是我在与非门科技工作时候的几个php shell应用,抛砖引玉,希望大家能学会这些简单但又适用的技能。

$root = “/var/www/”;
$bakdir = “/var/wwwbak/”.date(”Y-m-d”);
$dir = array(”***.eefocus.com”,”***.eefocus.com”);
if(!is_dir($bakdir)){
mkdir($bakdir);
}
foreach($dir as $key=>$value)
{
exec(”tar zcf “.$bakdir.”/”.$value.”.tar.gz /var/www/”.$value);
#echo “tar zcf “.$bakdir.”/”.$value.”.tar.gz /var/www/”.$value.”
“;
}
?>

这是一个简单的网站目录备份程序,使用cron每天执行,自动tar压包备份网站。虽然很笨的方法,但网站安全系数提高了,这个过程也不用写啥bash去解决。

其实在php执行shell的时候,已经支持命令行参数了,这些应用下次分解。

参考网站:

http://www.phpbuilder.com/columns/darrell20000319.php3

http://www.php-cli.com/

centos5安装nginx+mysql+php fastcgi模式

作者 : admin 于 2008年05月18日, 12:20:01
2008
05-18
原教程 http://blog.s135.com/read.php/314.htm

安装环境:centos5.0 基本系统+开发工具

安装xml组件
yum install libxml2 libxml2-devel

编译安装 php
./configure –enable-fastcgi –enable-force-cgi-redirect
make && make install
————————————————————————–
[root@localhost php-5.2.5]# make install
Installing PHP SAPI module: cgi
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Console_Getopt – installed: 1.2.3
[PEAR] Archive_Tar – installed: 1.3.2
[PEAR] Structures_Graph- installed: 1.0.2
pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
[PEAR] PEAR – installed: 1.6.1
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/include/php/ext/pdo/
————————————————————————–
make test

yum安装mysql
yum install mysql mysql-devel mysql-server

复制spawn-fcgi 至 /usr/local/bin/
chmod +x spawn-fcgi

/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
使用spawn-fcgi监听127.0.0.1的10080端口 进程10 用户www
————————————————————————–
[root@localhost bin]# spawn-fcgi -a 127.0.0.1 -p 10080 -C 10 -u www -f php-cgi
X-Powered-By: PHP/5.2.5
Content-type: text/html
spawn-fcgi.c.211: child exited with: 0, Success
————————————————————————–
[root@localhost bin]# spawn-fcgi -a 127.0.0.1 -p 10080 -C 10 -u www -f php-cgi
spawn-fcgi.c.190: child spawned successfully: PID: 27936
————————————————————————–
安装pcre
yum install pcre pcre-devel
编译安装 nginx
./configure –user=www –group=www
————————————————————————–
Configuration summary
+ threads are not used
+ using system PCRE library
+ OpenSSL library is not used
+ md5 library is not used
+ sha1 library is not used
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “/usr/local/nginx/client_body_temp”
nginx http proxy temporary files: “/usr/local/nginx/proxy_temp”
nginx http fastcgi temporary files: “/usr/local/nginx/fastcgi_temp”
————————————————————————–
make && make install

touche /usr/local/nginx/conf/fcgi.conf
内容为
————————————————————————–
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
————————————————————————–
启动 nginx
ulimit -SHn 51200
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

配置开机自动启动Nginx + PHP
vi /etc/rc.local
在末尾增加以下内容:
ulimit -SHn 51200
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/bin/php-cgi
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

优化Linux内核参数
vi /etc/sysctl.conf
在末尾增加以下内容:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000

使配置立即生效:
/sbin/sysctl -p
在不停止Nginx服务的情况下平滑变更Nginx配置
修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t

这时,输入以下命令查看Nginx主进程号:
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’

至于日常维护,还不太清楚,咱们下次分解

—————————————————–
Nginx的编译参数如下:
[root@localhost]#./configure –prefix=/usr/local/server/nginx –with-openssl=/usr/include \
–with-pcre=/usr/include/pcre/ –with-http_stub_status_module –without-http_memcached_module \
–without-http_fastcgi_module –without-http_rewrite_module –without-http_map_module \
–without-http_geo_module –without-http_autoindex_module

 Page 4 of 4 « 1  2  3  4