| 100 系列(信息) |
| 100 |
Continue(客户端可以继续发送未发完的请求) |
| 101 |
Switch Protocals(服务端/客户端所使用的协议不一致) |
| 200 系列(成功) |
| 200 |
OK(成功) |
| 201 |
Created(已按请求创建新资源) |
| 202 |
Accepted(请求已被接受) |
| 203 |
Non-Authoritative Information(从第三方获取的信息) |
| 204 |
No Content(服务端没有可返回的数据) |
| 205 |
Reset Content(客户端需重置请求内容) |
| 206 |
Partial Content(服务端返回部分数据) |
| 300 系列(重定向) |
| 300 |
Multiple Choices(多个资源可用) |
| 301 |
Moved Permanently(资源已被移动) |
| 302 |
Found(临时在其他地址找到相应资源) |
| 303 |
See Other(在其他地址找到相应资源) |
| 304 |
Not Modified |
| 305 |
Use Proxy |
| 306 |
(Unused) |
| 307 |
Temporary Redirect |
| 400 系列(错误) |
| 400 |
Bad Request |
| 401 |
Unauthorized |
| 402 |
Payment Required |
| 403 |
Forbidden |
| 404 |
Not Found |
| 405 |
Method Not Allowed |
| 406 |
Not Acceptable |
| 407 |
Proxy Authentication Required |
| 408 |
Request Timeout |
| 409 |
Conflict |
| 410 |
Gone |
| 411 |
Length Required |
| 412 |
Precondition Failed |
| 413 |
Request Entity Too Large |
| 414 |
Request-URI Too Long |
| 415 |
Unsupported Media Type |
| 416 |
Requested Range Not Satisfiable |
| 417 |
Expectation Failed |
| 500 系列(服务器错误) |
| 500 |
Server Internal Error |
| 501 |
Not Implemented |
| 502 |
Bad Gateway |
| 503 |
Service Unavailable |
| 504 |
Gateway Timeout |
| 505 |
HTTP Version Not Supported |
参考资料:http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
开始还满怀信心的打算拿 Perl 写一个文件上传管理程序,可是在写完了登陆部分之后就泄气了。原因很简单,服务器不支持 CGI::Session,而我又不想花时间去研究 Perl Cookie。
login.cgi
- use strict;
-
- use DBI;
- use CGI;
- use Digest::MD5 qw(md5_hex);
-
- my $cgi = new CGI;
- my $user_name = $cgi->param('username');
- my $user_pass = $cgi->param('password');
- $user_name =~ s/(?:\012\015|\012|\015)//g;
- $user_pass =~ s/(?:\012\015|\012|\015)//g;
- $user_pass = md5_hex($user_pass);
- my $user_login = 0
-
- require "config.pm"
-
- our $db_host;
- our $db_use;
- our $db_user;
- our $db_pass;
- our $db_table;
-
- my $db_conn = DBI->connect("DBI:mysql:database=$db_use;host=$db_host","$db_user","$db_pass", {'RaiseError' => 1});
- print "Location: /error-503\n\n" unless $db_conn;
-
- my $sql = $db_conn->prepare("SELECT username FROM `$db_table` WHERE user_password='$user_pass'");
- $sql->execute() or print "Location: /error-503\n\n";
-
- while(my @result = $sql->fetchrow_array()) {
- if($user_name eq $result[0]) {
-
- $user_login = 1
- last;
- }
- }
-
- $db_conn->disconnect();
-
- print "Location: /error-401\n\n" unless $user_login;
-
- print "Content-type: text/plain\n\nYes !";
-
- exit(0);
其中登陆部分采用了《突发奇想,小改动解决安全问题》其中的方法。
看来要重操 PHP 旧业了……
这几天一直在琢磨用 Perl CGI 架设网站,正好在网上看到了一篇关于 CGI 安全的文章,里面提到了数据库注入和远程执行等等安全问题。也就是说,比较安全的方法是屏蔽一系列特殊字符(比如说,管道“|”、引号“" '”、斜线“/”等等)。今天偶然间突发奇想,如果换一种思路,不需要过滤特殊字符也能做到脚本安全。
具体方法如下。(假设:用户名与密码存在 user 表中,密码用 md5 加密)
Pseudo-code
- $username = http_get("username");
- $password = http_get("password");
-
- $password = md5($password);
-
- $mysql->connect();
- $rows = $mysql->query("SELECT username FROM `user` WHERE password='$password'");
-
- while($r = $rows->next()) {
- if($r->username == $username) login_success();
- }
- die("Username/password incorrect!");
由于 md5 hash 不包括任何特殊字符,所以这段脚本对数据库无害。
优点总结:由于传递给数据库的字符串当中不包括任何特殊字符,因此没有任何注入危险。
缺点总结:一般来说,用户数据表都是拿用户名做索引,所以按密码查询效率相对低一些。但是考虑到用户登录的频繁程度,这个缺点就无所谓了。
本文介绍了如何在Discuz! 5.5论坛系统中加入eMule下载功能。具体实例参考VeryCD。
阅读全文...
BOM: Byte Order Mark(字节顺序标记)
本来BOM是用来确定UTF-8文件的字序的(Big Endian/Little Endian)。但是,如果BOM设置不当,便会造成网站白屏。
阅读全文...