一般来说,FORM我们都是用POST方式提交的,但也有需要GET方式提交的表单.这种情况出现最多的就应该是Search了。。
如果没有采用框架,那么我们的搜索POST的action就可能是 search.php了。而如果采用框架,并且是单入口的框架,这样的Action地址往往可能是index.php?module=search&action=titlesearch之类。但如果你真的这样把这个URL放到action里面提交,你会发现,你所有的参数都扔到index.php?module=index&action=index这样的页面里去了。
这是为什么呢?其实就是因为form中,如果method是GET方式,它是不接受url后面带参数的,而是把form里的元素自己组成get参数进行传递。所以,如果需要用到get方式,请手动在表单中使用隐藏域把module和Action等赋值进去。
但凡是也有例外,单入口的PHP,如果使用pathinfo模式,好象就能 够规避这种问题,比如我的URL是index.php/module/search/action/titlesearch/这时候,框架就能够被正常接收了。原理嘛。。。。黑黑,自己想想喽。
其实我这篇勃客只是做个笔记而己,因为在做thinksns第三方开发的时候,想使用get方式做查询的时候遇到了这个问题,而thinksns的url_mode用的是兼容模式,所以就出现了这种情况。事后已经向流年提起,流年好象是说过在thinkphp的框架中想法改进一下url_mode=3,兼容模式下存在的这种问题。
或许,现在的SVN上,它已经改掉了吧?可惜我用的thinksns不能随便更新核 心,真痛苦。
由于自己更改了thinksns的部分核心内容,不得己,先记录下来,如果以后被thinksns官方所更改,那么,我就从其中去掉,否则。。。每次TS一更新,我都要重新更新这些地方
1、关于Ucenter的整合【主要是添加了API等,还有就是用户登录和退出那块,暂时不更换】
2、修改了/thinkphp/api/Model/AttachLWModel.class.php的upload方法【约 line:69】,在foreach($uploadinfo as $u)这个循环中,添加了
PHP代码
- $map['key'] = $u['key'];
主要原因是,这个api只能针对页面中的FILE上传表单处理,而且,都是同名字段的表单,这对我来说有点不方便,比如我的表单里有<input type="ffile" name="a"><input type="file" name="b">,这个API就不能工作,所以添加了这个变量处理: $u['key']这个键值在thinkPHP的upload里是存在的,所以直接添加就可以了。
而且这个变量的赋值,相信在以后的thinksns上传附件有多个不同字段的时候,应该是会用得到的。。。
这是一篇有点老的文章了,但是因为它带有译文,所以我就转摘一下。
命令行下的PHP,以前也是经常用的,现在用的少了。毕竟命令下行,效果更好,以前都是用来循环处理订单和检测无效信息的。。。
前两天我写了博客说bluehost的命令行不支持yii框架呢。。
以下是原文:
Author:Darrell Brogdon
As most of us already know, PHP is the best language for developing dynamic web pages available today. Not many people are aware that it can be used as a shell scripting language as well. While PHP as a shell script isn't as robust as Bash or Perl it does have definite advantages, especially if you're like me and are more proficient in PHP than you are in Perl.
The requirements for using PHP as a shell language is that you must compile PHP as a CGI binary instead of as an Apache module. There are certain security issues related to this so please refer to the PHP Manual when doing so.
Where the code is concerned, the only difference between a PHP shell script and a regular PHP web page is the existence of the standard shell call at the top of the script:
#!/usr/local/bin/php -q
We're using the '-q' switch so that the HTTP headers are suppressed. Also, you're still required to begin and end the script with the standard PHP tags:
<?php ?>
So let's delve into the standard code sample we all know and love:
#!/usr/local/bin/php -q
<?php
print("Hello, world!\n");
?>
This, as most of you know already (about a billion times over) will simply output to the screen "Hello, world!".
Passing arguments to the shell script
Commonly with a shell script you need to pass arguments to the script. This is easily done using the built-in '$argv' array as show in the following example:
#!/usr/local/bin/php -q
<?php
$first_name = $argv[1];
$last_name = $argv[2];
print("Hello, $first_name $last_name! How are you today?\n");
?>
So in the above script we're printing out the first two arguments to the script which would be called like this:
[dbrogdon@artemis dbrogdon]$ scriptname.ph Darrell Brogdon
Which would print out:
Hello, Darrell Brogdon! How are you today?
[dbrogdon@artemis dbrogdon]$
The only major difference with the '$argv' array between a shell script and a web page is that in a shell script, '$argv[0]' is the name of your script. In a web page it is the first argument in your query string.
Making a script more interactive
But how do we wait for user input? How do we create a truly interactive script? Well, PHP has no native functions like the 'read' command in shell but we can always emulate it using the following PHP function:
*Note that this function will only work for Unix.
<?php
function read() {
$fp=fopen("/dev/stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return $input;
}
?>
This function opens a file pointer to Standard In (/dev/stdin on Linux) and reads anything from this pointer up to 255 bytes, newline, or EOF. In this case a newline is most likely to occur. It then closes the file pointer and returns the data.
So now let's modify our previous script to wait for user input using the newly created 'read()' function:
#!/usr/local/bin/php -q
<?php
function read() {
$fp=fopen("/dev/stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return $input;
}
print("What is your first name? ");
$first_name = read();
print("What is your last name? ");
$last_name = read();
print("\nHello, $first_name $last_name! Nice to meet you!\n");
?>
You may notice, however, that when you execute this script the last line to be printed is broken into three lines instead of one as it should be. This is because our 'read()' function also takes in the newline character. This is easily fixed by stripping off the newline before we return the data:
<?php
function read() {
$fp=fopen("/dev/stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return str_replace("\n", "", $input);
}
?>
Embedding PHP shell scripts within a regular shell script
Sometimes it might be handy to embed a PHP shell script within a script written in Bash or other shell. This is fairly simple but can get a tad tricky.
First, how to embed the PHP code:
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
print("This is the PHP section of the code\n");
?>
EOF
Pretty simple huh? Until you add a variable that is. This is the tricky part. Try running the following code segment:
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
$myVar = "PHP";
print("This is the $myVar section of the code.\n");
?>
EOF
You'll get the following error:
<b>Parse error</b>: parse error in <b>-</b> on line <b>2</b><br>
To fix this you have to escape all of the '$' characters in your PHP code:
#!/bin/bashecho This is the Bash section of the code./usr/local/bin/php -q << EOF<?php \$myVar = "PHP"; print("This is the \$myVar section of the code.\n");?>EOF
So that should get you started on creating your own shell scripts using PHP!
译文:
可能很多人都想过使用PHP编写一些定时发信之类的程序,但是却没有办法定时执行PHP;一次去PHPBuilder的时候,发现了这一篇文章,于是想给大家翻译一下(同时做了一些修改),希望对大家有用。第一次翻译文章,不好请多多见谅。
我们都知道,PHP是一种非常好的动态网页开发语言(速度飞快,开发周期短……)。但是只有很少数的人意识到PHP也可以很好的作为编写Shell脚本的 语言,当PHP作为编写Shell脚本的语言时,他并没有Perl或者Bash那么强大,但是他却有着很好的优势,特别是对于我这种熟悉PHP但是不怎么 熟悉Perl的人。
要使用PHP作为Shell脚本语言,你必须将PHP作为二进制的CGI编译,而不是Apache模式;编译成为二进制CGI模式运行的PHP有一些安全性的问题,关于解决的方法可以参见PHP手册(http://www.php.net)。
一开始你可能会对于编写Shell脚本感到不适应,但是会慢慢好起来的:将PHP作为一般的动态网页编写语言和作为Shell脚本语言的唯一不同就在于一个Shell脚本需要在第一行生命解释本脚本的程序路径:
#!/usr/local/bin/php -q
我们在PHP执行文件后面加入了参数“-1”,这样子PHP就不会输出HTTPHeader(如果仍需要作为Web的动态网页,那么你需要自己使用header函数输出HTTPHeader)。当然,在Shell脚本的里面你还是需要使用PHP的开始和结束标记:
<?php 代码 ?>
现在让我们看一个例子,以便于更好的了解用PHP作为Shell脚本语言的使用:
#!/usr/local/bin/php -q
<?php
print("Hello, world!\n");
?>
上面这个程序会简单的输出“Hello, world!”到显示器上。
一、传递Shell脚本运行参数给PHP:
作为一个Shell脚本,经常会在运行程序时候加入一些参数,PHP作为Shell脚本时有一个内嵌的数组“$argv”,使用“$argv”数组可以很 方便的读取Shell脚本运行时候的参数(“$argv[1]”对应的是第一个参数,“$argv[2]”对应的是第二个参数,依此类推)。比如下面这个 程序:
#!/usr/local/bin/php -q
<?php
$first_name = $argv[1];
$last_name = $argv[2];
printf("Hello, %s %s! How are you today?\n", $first_name, $last_name);
?>
上面的代码在运行的时候需要两个参数,分别是姓和名,比如这样子运行:
[dbrogdon@artemis dbrogdon]$ scriptname.ph Darrell Brogdon
Shell脚本在显示器上面会输出:
Hello, Darrell Brogdon! How are you today?
[dbrogdon@artemis dbrogdon]$
在PHP作为动态网页编写语言的时候也含有“$argv”这个数组,不过和这里有一些不同:当PHP作为Shell脚本语言的时候“$argv[0]”对 应的是脚本的文件名,而当用于动态网页编写的时候,“$argv[1]”对应的是QueryString的第一个参数。
二、编写一个具有交互式的Shell脚本:
如果一个Shell脚本仅仅是自己运行,失去了交互性,那么也没有什么意思了。当PHP用于Shell脚本的编写的时候,怎么读取用户输入的信息呢?很不 幸的是PHP自身没有读取用户输入信息的函数或者方法,但是我们可以效仿其他语言编写一个读取用户输入信息的函数“read”:
<?php
function read() {
$fp = fopen('/dev/stdin', 'r');
$input = fgets($fp, 255);
fclose($fp);
return $input;
}
?>
需要注意的是上面这个函数只能用于Unix系统(其他系统需要作相应的改变)。上面的函数会打开一个文件指针,然后读取一个不超过255字节的行(就是fgets的作用),然后会关闭文件指针,返回读取的信息。
现在我们可以使用函数“read”将我们前面编写的程序1修改一下,使他更加具有“交互性”了:
#!/usr/local/bin/php -q
<?php
function read() {
$fp = fopen('/dev/stdin', 'r');
$input = fgets($fp, 255);
fclose($fp);
return $input;
}
print("What is your first name? ");
$first_name = read();
print("What is your last name? ");
$last_name = read();
print("\nHello, $first_name $last_name! Nice to meet you!\n");
?>
将上面的程序保存下来,运行一下,你可能会看到一件预料之外的事情:最后一行的输入变成了三行!这是因为“read”函数返回的信息还包括了用户每一行的结尾换行符“\n”,保留到了姓和名中,要去掉结尾的换行符,需要把“read”函数修改一下:
<?php
function read() {
$fp = fopen('/dev/stdin', 'r');
$input = fgets($fp, 255);
fclose($fp);
$input = chop($input); // 去除尾部空白
return $input;
}
?>
三、在其他语言编写的Shell脚本中包含PHP编写的Shell脚本:
有时候我们可能需要在其他语言编写的Shell脚本中包含PHP编写的Shell脚本。其实非常简单,下面是一个简单的例子:
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
print("This is the PHP section of the code\n");
?>
EOF
其实就是调用PHP来解析下面的代码,然后输出;那么,再试试下面的代码:
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
$myVar = 'PHP';
print("This is the $myVar section of the code\n");
?>
EOF
可以看出两次的代码唯一的不同就是第二次使用了一个变量“$myVar”,试试运行,PHP竟然给出出错的信息:“Parse error: parse error in - on line 2”!这是因为Bash中的变量也是“$myVar”,而Bash解析器先将变量给替换掉了,要想解决这个问题,你需要在每个PHP的变量前面加上“\” 转义符,那么刚才的代码修改如下:
#!/bin/bash
echo This is the Bash section of the code.
/usr/local/bin/php -q << EOF
<?php
\$myVar = 'PHP';
print("This is the \$myVar section of the code\n");
?>
EOF
好了,现在你可以用PHP编写你自己的Shell脚本了,希望你一切顺利。如果有什么问题,可以去http://www.PHPBuilder.com或者http://www.zPHP.com上面讨论。
---EOF---
仔细看上面的一段, fopen("/dev/stdin"),如果你看过yii的框架,你会发现,现在很多人都在使用php://stdin,其实,这只是PHP把这种封装成了一个协议,更方便而己。。可以参考yiiframework.com
影响版本:
PHP PHP 5.3.x
PHP PHP 5.2.x漏洞描述:
BUGTRAQ ID: 36555
CVE ID: CVE-2009-3557
PHP是广泛使用的通用目的脚本语言,特别适合于Web开发,可嵌入到HTML中。
PHP的tempnam()中的错误可能允许绕过safe_mode限制。以下是ext/standard/file.c中的有漏洞代码段:
C++代码
- PHP_FUNCTION(tempnam)
- {
- char *dir, *prefix;
- int dir_len, prefix_len;
- size_t p_len;
- char *opened_path;
- char *p;
- int fd;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &dir, &dir_len,
- &prefix, &prefix_len) == FAILURE) {
- return;
- }
-
- if (php_check_open_basedir(dir TSRMLS_CC)) { [1]
- RETURN_FALSE;
- }
-
- php_basename(prefix, prefix_len, NULL, 0, &p, &p_len TSRMLS_CC);
- if (p_len > 64) {
- p[63] = ’\0’;
- }
-
- if ((fd = php_open_temporary_fd(dir, p, &opened_path TSRMLS_CC)) >= 0) {
- close(fd);
- RETVAL_STRING(opened_path, 0);
- }
- efree(p);
- }
在[1]处tempnam()函数仅检查了open_basedir值。<*参考 http://securityreason.com/securityalert/6601 ,http://secunia.com/advisories/37412/ *>
厂商补丁:
PHP
---
目前厂商已经发布了升级补丁以修复这个安全问题,请到厂商的主页下载:
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_2/ext/standard/file.c?view=log
http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/standard/file.c?view=log
消息来源:http://hi.baidu.com/isbx/blog/item/9607b3fbdb3988284e4aea53.html
不过,原作者的标题写错了。应该是tempnam函数,呵呵
做WEB开发的,总不可避免的会利用程序来发邮件。。
而163的邮局相对的比较完善,他提供了一些错误代码和一些其他帮助。
你看:163邮箱OutLook错误号解析一文中,就提到了很多代码,他增强了你在开发中的纠错能力:
一般常见错误代码 |
0x800C0131 |
可能是 Folders.dbx 档案属性错误或损坏. |
0x800CCC00 |
身份验证(Authentication)未载入 |
0x800CCC01 |
认证(Certificate)内容错误 |
0x800CCC02 |
认证日期错误 |
0x800CCC03 |
使用者已联机 |
0x800CCC05 |
未联机到服务器 |
0x800CCC0A |
邮件下载未完成 |
0x800CCC0B |
服务器忙碌中 |
0x800CCC0D |
找不到主机(检查你的SMTP服务器是不是设错) |
0x800CCC0E |
联机到服务器失败,无法与主机建立联机。等一段时间再试。 |
0x800CCC0F |
服务器结束联机(对方服务器负荷过重) |
0x800CCC10 |
服务器无法辨认此邮件地址 |
0x800CCC11 |
服务器无法辨认的 Mailing list |
0x800CCC12 |
无法传送 Winsock request |
0x800CCC13 |
无法接收 Winsock reply |
0x800CCC14 |
无法起始 Winsock |
0x800CCC15 |
无法开启 Windows Socket |
0x800CCC16 |
无法辨认使用者账号,使用者账号错误 |
0x800CCC17 |
使用者中断操作 |
0x800CCC18 |
登入失败(例如:不需要安全密码认证登入,但却设了安全密码认证登入) |
0x800CCC19 |
作业逾时 |
0x800CCC1A |
无法以 SSL 建立联机 |
|
|
Winsock错误 |
0x800CCC40 |
Network subsystem 无法使用 |
0x800CCC41 |
Windows Sockets 不支持此应用程序 |
0x800CCC43 |
Bad address. |
0x800CCC44 |
Windows Sockets 无法加载 |
0x800CCC45 |
Operation now in progress.. |
|
|
SMTP错误 |
0x800CCC60 |
不合法的回应 |
0x800CCC61 |
不明的错误代码 |
0x800CCC62 |
收到语法错误 |
0x800CCC63 |
语法参数不正确 |
0x800CCC64 |
指令不完整 |
0x800CCC65 |
不正确的指令序列 |
0x800CCC66 |
指令不完整 |
0x800CCC67 |
没有这个指令 |
0x800CCC68 |
邮件信箱被锁住或忙碌中 |
0x800CCC69 |
找不到邮件信箱 |
0x800CCC6A |
处理要求错误 |
0x800CCC6B |
邮件信箱不在此服务器上 |
0x800CCC6C |
已无空间储存邮件 |
0x800CCC6D |
已超过限制的储存容量上限 |
0x800CCC6E |
不合法的邮件信箱名称 |
0x800CCC6F |
Transaction error,可能是服务器不接受你的邮件,请跟你的 ISP 联络。 |
0x800CCC78 |
邮件地址不正确,收件者被服务器拒绝,在属性里选中“我的服务器需要身份验证”即可。 |
0x800CCC79 |
Relay Denied:Outlook Express 的 SMTP 设定不正确,在属性里选中“我的服务器需要身份验证”即可。 |
0x800CCC7A |
没有指定寄件者 |
0x800CCC7B |
没有指定收件者 |
|
|
POP3错误 |
0x800CCC90 |
检查是否有使用该服务器的权限。或是否设了安全密码认证登入 |
0x800CCC91 |
使用者名称错误或找不到此使用者 |
0x800CCC92 |
账号、密码错误,请核实帐号和密码的输入是否正确。 |
0x800CCC93 |
无法解释响应 |
0x800CCC94 |
需要指令 |
0x800CCC95 |
服务器上已无邮件 |
0x800CCC96 |
没有邮件标记为要下载 |
0x800CCC97 |
Message ID 超出范围 |
|
|
NNTP错误 |
|
0x800CCCA0 |
新闻服务器响应错误,可能你没有拥有可使用该服务器的权限。 |
0x800CCCA1 |
读取新闻群组失败 |
0x800CCCA2 |
要求服务器邮件清单失败 |
0x800CCCA3 |
无法显示清单 |
0x800CCCA4 |
无法开启群组 |
0x800CCCA5 |
服务器无此群组 |
0x800CCCA6 |
邮件不在服务器上 |
0x800CCCA7 |
找不到件标题 |
0x800CCCA8 |
找不到邮件本文 |
0x800CCCA9 |
无法发布到服务器上 |
0x800CCCAA |
无法开启下封邮件 |
0x800CCCAB |
无法显示日期 |
0x800CCCAC |
无法显示标题 |
0x800CCCAD |
无法显示 MIME 标题 |
0x800CCCAE |
使用者名称或密码不正确 |
|
|
RAS错误 |
0x800CCCC2 |
未安装拨号网络 |
0x800CCCC3 |
找不到拨号网络 |
0x800CCCC4 |
拨号网络错误 |
0x800CCCC5 |
Connectoid 坏或遗失 |
0x800CCCC6 |
取得拨号设定时错误 |
|
|
IMAP错误 |
0x800CCCD1 |
登入失败 |
0x800CCCD2 |
Message tagged |
0x800CCCD3 |
Invalid response to request. |
0x800CCCD4 |
语法错误 |
0x800CCCD5 |
不是 IMAP 服务器 |
0x800CCCD6 |
Buffer 已超过上限 |
0x800CCCD7 |
Recovery error |
0x800CCCD8 |
数据不完整 |
0x800CCCD9 |
联机被拒 |
0x800CCCDA |
不明的回应 |
0x800CCCDB |
User ID 已更改 |
0x800CCCDC |
User ID 指令失败 |
0x800CCCDD |
Unexpected disconnect |
0x800CCCDE |
Invalid server state |
0x800CCCDF |
无法认证客户端 |
而对于那些喜欢手动查看从邮件服务器到网易MX服务器的SMTP的记录的朋友,163邮箱的帮助也做了介绍:
利用telnet手工模拟一次smtp会话过程,能提供许多有用的信息,从而帮助我们迅速定位您的问题。下面这个手工smtp会话测试过程可以在多个操作系统下运行,包括Windows、Unix和Linux。
2nn开头的返回码,表示会话是正常的;而5nn或者4nn开头的返回码则表示有错误发生。
利用telnet来模拟一次完整的发信,下面是具体步骤:
·打开一个命令窗口,键入:telnet 163mx01.mxmail.netease.com 25,这条命令将建立一个到我们163邮件服务器的连接;
·键入:HELO yourdomain.com 这里的yourdomain.com指您的域名;
·键入:MAIL FROM:< you@yourdomain.com >(邮箱名需要用<>括起来),这里的you@yourdomain.com指您们域的一个邮箱名;
·键入:RCPT TO:< postmaster >(邮箱名需要用<>括起来),这将发信到我们的postmaster邮箱;
·键入:DATA;
·输入邮件的信头和正文;
Received: (from you@yourdomain.com) by yourdomain.com
FROM:< you@yourdomain.com>(无需空格)
TO:< postmaster>(无需空格)
SUBJECT: yourdomain.com to netease
(空行)
Hi!
It's from yourdomain.com. Just a test.Bye.
·新起一个空行,键入:. 然后按回车,这将结束整封信,并发送给服务器。
范例(模拟从126.com服务器向网易163.com发起smtp会话)如下图:
当然:该测试过程必须在发信服务器上进行。