PHP

浏览模式: 标准 | 列表 | 图文
为windows的WEB服务器添加高性能的FTP组件

为windows的WEB服务器添加高性能的FTP组件

在windows服务器里面,如果我们要用FTP函数,速度应该是很慢的,而且效率不高,如果有大量文件需要上传,用自带的FTP函数,恐怕是要死人的吧。
windows服务器,windows哦,可以装N多软件的windows哦。虽然不建议在服务器上装上很多软件,但是也可以装一些FTP软件的嘛。这里以cuteftp举例。
cuteftp安装完毕后,会在软件目录里有一个Scripts目录,现在的版本不象很久以前的了,如今的版里只有一个Sample.vbs,记得几年前的cuteftp里面会有各种各样的vbs文件的。
闲话不多说,打开vbs文件,内容为:

'This default template script is in VBScript. You can write scripts in your language of choice and save them with the proper extension, or use your an editor specific to that language.
'See the TESDK help file for more details on how the scripting feature works and for information on each supported method and property.
'You must have Windows Scripting Host installed for the COM enabled engine to work. Run the Transfer Engine once to register it (as a COM object) on the target system.
'If you're having problems with running scripts while not logged in, or when trying to run them using MS scheduler, refer to our online knowledgebase for help (http://www.globalscape.com/support)
'Look into c:\temp folder to observe local activity (for testing purposes) or right click on the Transfer Engine icon in the systray and select "show current transfers"
'This sample script performs an anonymous login to ftp://ftp.globalscape.net
'First declare a variable called Mysite. This will hold the reference to the TE COM object.
Dim MySite
'Create a connection object and assign it to the variable
Set MySite = CreateObject("CuteFTPPro.TEConnection")
' Now set each property for the site connection
' You can omit this section to use the default values, but you should at least specify the Host
'The default Protocol is FTP, however SFTP (SSH2), FTPS (SSL), HTTP, and HTTPS can also be used)
MySite.Protocol = "FTP"
MySite.Host = "ftp.globalscape.com"
'following lines are optional since the default is anonymous if no login and password are defined
MySite.Login = "anonymous"
MySite.Password = "user@user.com"
'if necessary, use the UseProxy method and ProxyInfo or SocksInfo properties to connect through a proxy server
MySite.UseProxy = "BOTH"
'now connect to the site (also called called implicitly when most remote methods are called)
MySite.Connect
'perform some logic to verify that the connection was made successfully
If (Not Cbool(MySite.IsConnected)) Then
MsgBox "Could not connect to: " & MySite.Host & "!"
Quit(1)
End If
'The script will now check to see if the local folder c:\temp exists and will create it if necessary
If (Not (MySite.LocalExists("c:\temp"))) Then
MySite.CreateLocalFolder "c:\temp"
End If
'Change TE's local working folder to to c:\temp
MySite.LocalFolder = "c:\temp"
'Check for existence of remote folder "/pub/cuteftp"
b = MySite.RemoteExists("/pub/cuteftp/")
If (Not CBool(b)) Then
'Verify existence of remote folder
MsgBox "Remote folder not found!. Please make sure that the Pub folder exists on the remote site"
Quit(1)
End If
'Now download the index file to the local destination folder
MySite.Download "/pub/cuteftp/index.txt"
'Complete. Show the status of this transfer.
MsgBox "Task done, final status is '" + MySite.Status + "'"
MySite.Disconnect
MySite.Close
'End of sample script. You can save you script and then run it by either selecting it from the Tools > Run Script menu or by double clicking on the script file in Windows

看到这样的文件,你应该知道如何调用一些FTP软件自带的方法了吧?

由于windows版本下的PHP直接就支持COM,所以现在我们可以直接用PHP模拟一遍:

<?php

$ftp = new COM("CuteFTPPro.TEConnection");

$ftp->Protocol = "FTP";
$ftp->Host = "ftp.globalscape.com";

$ftp->Login = "anonymous";
$ftp->Password = "user@user.com";

$ftp->UseProxy = "BOTH";
$ftp->Connect();

if ( !$ftp->IsConnected ){
die("Could not connect to : {$ftp->Host}");
}

if ( !$ftp->LocalExists('c:\\temp') ){
$ftp->CreateLocalFolder('c:\\temp');
}

$ftp->LocalFolder = 'c:\\temp';

$remote = $ftp->RemoteExists('/pub/cuteftp/');
if ( !$remote ){
die('Remote folder not found!. Please make sure that the Pub folder exists on the remote site');
}

$ftp->Download('/pub/cuteftp/index.txt');
echo( 'Over,ftp Status:' . $ftp->Status );
$ftp->Disconnect();
$ftp->Close();


?>

执行一下,OK,显示:Over,ftp Status:FINISHED,同时c盘根目录下有一个temp目录,里面下载了那个:index.txt文件。测试完毕。。(PS:对于这样的转换实在没有技术含量啊。呵呵,直接把“.”换成“->”就完事了。)
更多的函数,请参考cuteftp帮助文件:

5c935efdda14f3d98286d16baf2239f2

佛家思想与PHP开发

今天听了点课,感悟还是有点的。软件开发会时不时的遇到点瓶颈,这其实与佛家思想还是有点关系的,当然,也许是我硬套上的吧。

佛家参惮有一种说法:看山是山,看水是水;看山不是山,看水不是水;看山还是山,看水还是水。这里说的是佛家修行的三个层次,也叫三重境界,即初期看山是山,中期有悟时,山就不再是简单的山了,最后彻悟,返朴归真,山还是山,但已经不是原来的那个山了,升华了,空灵了。把这用在游记上也是很合适的。走马观花,照象机式的记录,见山是山,见水是水,见什么写什么,流水帐,千篇一律,大同小异,这是初级阶段。再上一个层次,进到文学的创作,那就得看山不是山,看水不是水。那是什么?是山水背后的东西,附在山水之上的东西,山不再是单纯岩石泥土加草木的立体,水也不是简单的流动的液体了。

软件开发也差不多,刚开始学程序的时候,看山是山,因为这时候思想还没有成形,对于程序的理解都是停在表面上,没有什么特别的概念。随着编程时间的增长,和能力的进步,这时候看待程序、架构都比较的深层次了,于是就升级成为看山不是山,看水不是水的境界。这道坎其实很难跨越,等到真正跨越这一层,然后所以的编程语言、架构在眼里又变成那样的浅显,于是又回到了最初的看山是山看水是水的境界。

随便说说而己。不必生搬硬套

开发人员的七种心态——支付宝杨云

开发人员的七种心态——支付宝杨云

今天下午和同事参加了ThinkSite举办的技术交流会,期间由某知名猎头公司猎头进行了行业介绍和职业规划简介,但最关心的还是支付宝架构师杨云的介绍。

杨云认为:

1、开发者应当尝试不同的应用开发,以便可以了解、熟悉各种流程。
2、始终保持初学者心态。在看到别人的开发、代码时,不管怎么样,总应该抱着学习的心态,不能因为自己在某领域强过别人就对别人采用批判的眼光。三人行必有我师。达者为先。讲的都是这种道理吧。
3、建立完善的学习体系。当你看到或者搜索到你需要的代码或者程序时,不应该存着拿来主义,而应该做到知其然,并知其所以然。只有这样,你才是真正的学习到了东西,否则永远就只是处在代码层阶段,而永远无法深入。
4、少用工具代替思考,工具之所以是工具,只是为了方便开发,而不能将工具代替你自身的思考。开发过程中,总会出现这样那样的BUG,工具只是方便你将BUG定位,而不一定能完整的将BUG查找出来,这时候不能完全依赖工具,而应该检查自己的代码。
5、不要错过向高手学习的机会。记住,是主动向高手学习。生活当中、开发当中,遇到高手的机会可能会很多,但能不能抓住机会向别人请教,那就要靠自己了。毕竟,别人不会主动问你有什么不会的。
6、搞清技术的来龙去脉。编程技术的发展经历了大约三十年左右,在这三十年里,产生了各种不同的思想,也有很多人根据同样的思想而发展出了不同的派系,只有了解清楚该项技术产生的背景,就不会让你在选择的时候感到迷惑。举例说AJAX,本来就是属于一个很老的技术,但现在ajax的框架有一大堆,你会选择哪个?如果你自己真正的了解了AJAX的核心的内容,你还会在于你选择哪一个吗?当然你在分析不同的代码后,可能会选择一个你认为相对效率较高的一样,可是这也证明了你基本搞清楚它的来龙去脉 了。
7、形成自己的开发的世界观。相信自己,不要迷惑,要有自己的世界观。这是杨云的意见和建议。个人还是认为:世界观、人生观、价值观,这虽然是在初中学政治的时候用到,但用在开发上,也确实有它的独到之处。这三个观念树立好,也可以使自己在往后的开发生涯中不会感到迷惘。这可是自己选择的路。。。。

附上杨云的演讲形象:

29cd0a76a415a69ccddd400f8911d926

会后,多人对世界观提出了自己的看法,当然我的看法就在上面。同时参与了一些讨论,感慨于目前的培训机构和培训人员及被培训人员的思维。虽然谈了不少,但总感觉少了点什么?文人相轻,在搞技术的人身上也能得到完美的体现。或许就其实就是杨云所说的第二条吧。没有一个初学者的心态,如何能够正确树立和形成一个完善的软件开发世界观?

学习,沉淀,尽可能的帮助其他人,或者这也是程序员的一种快乐吧。如果这种快乐能够被传递,那才是一件很快乐的事。

修复:使用chrome在Sablog里面发博文

原来我一直以为不能够在chrome下的Sablog里面使用fck editor,直到coolcode.cn的andot在群里说改了点东西就支持了。

原来fckeditor.js里面有

this.enableSafari =false;
this.enableOpera = false;

于是,将这两行改成了true;

然后修改那两个PHP文件,在IsCompatible方面里面的判断加上

else if ( strpos($sAgent, 'Opera/') !== false )
{
$fVersion = (float)substr($sAgent, strpos($sAgent, 'Opera/') + 6, 4) ;
return ($fVersion >= 9.5) ;
}
else if ( preg_match( "|AppleWebKit/(\d+)|i", $sAgent, $matches ) )
{
$iVersion = $matches[1] ;
return ( $matches[1] >= 522 ) ;
}

于是,世界清静多了,菜单也出来了。

感谢andot给我们提供的方法。。。

不愿意手工改的朋友,可以直接到:

http://www.coolcode.cn/show-305-1.html

进行下载。good Luck for you

让我吃惊的:phpinfo跨站脚本漏洞

让我吃惊的:phpinfo跨站脚本漏洞

从未想过,phpinfo页面居然有这么大的漏洞,在我想来,这纯粹是一个输出页面,怎么会有漏洞呢?
看了

漏洞说明: php是一款被广泛使用的编程语言,可以被嵌套在html里用做web程序开发。phpinfo()是用来显示当前php环境的一个函数,许多站点和程序 都会将phpinfo放在自己的站点上或者在程序里显示,但是phpinfo里存在一些安全问题,导致精心构造数据就可以产生一个跨站脚本漏洞,可以被用 来进行攻击。

漏洞成因: phpinfo页面对输入的参数都做了详细的过滤,但是没有对输出的进行charset的指定,而在一些浏览器里如IE7里,你可以让它自动选择编码或者通过一个iframe页面给它指定编码,这样就可以饶过phpinfo的过滤而产生一个跨站脚本漏洞。
漏洞来源: http://www.80sec.com/release/phpinfo-xss.txt
漏洞利用: 利用代码如下:


<html>
<head>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-7">
</head>
<body>
<iframe src="http://www.80sec.com/phpinfo.php?+ADw-SCRIPT+AD4-alert(document.domain);+ADw-/SCRIPT+AD4-=1">

以上代码在IE7+php 5.2.6测试成功。phpinfo页面的xss甚至比其他页面更加危险,因为如果有phpinfo的存在,恶意攻击者可以利用phpinfo的输出bypass如httponly和一些基础认证。

漏洞影响: 影响所有版本的php和浏览器IE7
漏洞修补: 建议暂时删除站点的phpinfo页面避免被人利用。

太吃惊了

[翻译][未完成版本]Developing Desktop Applications in PHP for Beginners.

[翻译][未完成版本]Developing Desktop Applications in PHP for Beginners.

Introduction:
简价

We have been creating web-applications using PHP since it came into existence, now we can also develop Desktop or Stand alone Applications with PHP-GTK. Desktop Applications are one which does not need either a Web Server like IIS, Apache, PWS etc. or a web browser for their execution. One of the reasons why Java is so popular is because it can be used to build applications, web pages, applets and beans that can run on several platforms including Windows, Linux and Solaris. Java runs a virtual machine called JVM, and code is compiled into an intermediate format known as Java byte code, which is platform independent. When that particular piece of code is executed within the JVM, the JVM optimizes the code for the particular platform on which it is running as it is being compiled.
从PHP产生到现在,我们一直都是使用它创建WEB应用,如今,我们也可以使用PHP-GTK来创建桌面或者其他杰出的应用。桌面程序不再依靠WEB服务器(比如IIS、APACHE、PWS等等)或者通过浏览器运行他们。JAVA为什么这么流行其中之一的原因就是他不仅可以创建程序、WEB应用,小应用程序Applets和Beans,而是他可以运行在windows、linux和solaris平台上。当这些特定的代码在JVM上运行的时候,JVM会在编译的时候针对特定联台而对代码进行优化。

Microsoft's latest technology, .NET follows the same principles. Code is compiled into Microsoft Intermediate Language (MSIL) and is then executed within the .NET framework as an application domain. Microsoft is hoping to standardize C# and MSIL so that .NET code can run cross platform.

微软最近的技术声称,.net一直遵循着同样的工作原因,代码被编译成MSIL并且运行在.net framework上。微软一直希望C#和MSIL能够标准化,这样.net下的代码也就能够相对的跨平台运行了。

So what has all of this got to do with PHP-GTK? Well, both Java and .NET can be used to build windowed applications and web pages. Thanks to PHP-GTK, we can now build cross platform windowed applications with PHP as well.

可是这和使用PHP-GTK又有什么关系呢?OK,java和.net都能够创建“窗口式应用”(桌面应用软件)和网页。感谢PHP-GTK,我们也可以使用PHP创建跨平台的“winform应用”(windowed applications一直不知道怎么翻译比较好,下面如果再提到,我想,我还是用桌面应用软件来代替吧。)。

What is PHP-GTK?
PHP-GTK是什么?

GTK is an acronym for the GIMP Toolkit and GIMP is an acronym for GNU Image Manipulation Program, and is a fully featured graphics editing program that runs on Linux. It has many (if not all) of the features of popular Windows programs such as Photoshop and Paint shop. It's the graphics editor of choice for most Linux users.

GTK是GIMP ToolKit(GIMP工具包)的缩写,同时GIMP又是GNU Image Manipulation Program(开源图像处理软件)的缩写,是一个可以运行在LInux下的一款图像编辑程序。它拥有与windows平台下的photoshop和画笔程序一些相同的功能,但并非全部。它是大多数Linux用户所选择的图形编辑工作。

GTK is actually part of a set of libraries that was written in C called GTK+. GTK+ was built up over time and is now a main part of Gnome, which is a Linux GUI desktop environment. GTK+ is based on an object-oriented nature and also includes two other libraries:
GTK实际上是一套用C语言编码的代码库,一般称为GTK+。GTK+一直以来就是Gnome(Linux图形界面)的重要部件之一。GTK+采用了面向对象的方面,并且引入其他两个重要的库:

  1. GLib: A library of tools that can be used to assist developers when creating applications with GTK+.
  2. GDK: Similar to GDI for Win32, GDK standard for GIMP drawing kit and wraps a set of lower level drawing functions into classes that make developing applications with GTK+ easier. If you're thinking along the lines of MFC for C++ then you're making a fair comparison: MFC wraps several controls and hides the calls to the underlying Windows API's from the developer. GDK does the same thing for GTK+.

Where to get?

We can download binary as well as source code version of PHP-GTK from http://gtk.php.net/download.php . As a beginner, it would be a difficult process to download and install in this manner. Where we need to set up another php.ini file for PHP-GTK. Instead there is another way of installing it. We can get PHP-GTK2 in an executable form as we get WAMP.EXE. (Windows, Apache, Mysql, PHP) All we have to do is just download just download the files from http://www.gnope.org/download.php ,unzip them and double click on the icon GnopeSetup-1.5.1.exe . It will run through a step by step process where it will set up PHP-GTK automatically.

How to test the installation?

Once the installation is done we would eager to know about what is special in it? When we install PHP we would run phpinfo () from root directory .For this let us run a sample script which displays Hello world (as usual) .we can use Dreamweaver for editing the code. Another important point to be kept in mind is to save the file with extension .phpw it can be saved anywhere on your hard disk.

Here is the sample code:

<?PHP
if (!class_exists('gtk')) {
die("Please load the php-gtk2 module in your php.ini");
}
$wnd = new GtkWindow();
$wnd->set_title('Hello world');
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));
$lblHello = new GtkLabel("hello world");
$wnd->add($lblHello);
$wnd->show_all();
Gtk::main();
?>

I have saved this sample file with the name hello.phpw at c:\test\. We should run this sample code from command line interface. (CLI) There may be a question rising in your mind asking, why we should run through command prompt than by just by double clicking it as it is a stand alone application. It is possible, for that we need to have a PHP compiler which converts our PHP-GTK code to EXE file . For now, let us try running it from the command prompt.
现在我们将上面这段代码保存在c:\test\目录下,取名为:hello.phpw。我们可以在命令行下运行它。或许你会有疑问,为什么我们不是编译成一个正常的程序,可以通过双击来运行?当然,这不是问题,那样的话,我们需要通过我们的PHP-GTK程序把PHP代码转换成EXE文件。现在,让我们尝试运行一下这个命令行先。

Steps for Executing a sample code:
执行部骤

  1. Start -> Run -> cmd (for xp sp2 and later version) or command (for windows 98).
    点击开始菜单->运行,输入cmd,如果是windows2000以前的版本,请输入command。
  2. Now you could see a black window which is Command Prompt. Key in the following commands as shown below.
z:>c:
c:> cd test
c:\test>php hello.phpw

Once we finish this line and hit the Enter key, we should see the desired output.

This shows the successful installation of PHP-GTK2 and shouls us PHP output without a web-browser.

Some interesting Websites on PHP-GTK:

  1. http://www.kksou.com/php-gtk2/
  2. http://phpgtk.activeventure.com/gtk/gtk.gtkbox.html (describes about all base classes).
  3. http://gtk.php.net/download.php
  4. http://www.gnope.org/download.php

用PHP取得文件后缀名

上传的时候,判断文件后缀名,然后再同时生成复杂名字的时候,总是会有烦恼,也确实是,使用PHP取文件后缀名的方法太多了。。这里稍列几个

1、

<?php
$urlname = 'http://www.neatcn.com/attachment/test.gif';
$path_info = pathinfo($urlname );
echo $path_info['extension'];
?>
2、discuz里面利用strrchr取得后缀名
function fileext($filename) {
return trim(substr(strrchr($filename, '.'), 1, 10));
}
//个人建议在$filename上加上basename(),这样可以对路径也处理一下
3、利用end函数
$filename = 'http://www.neatcn.com/attachments/test.gif';
echo(end(explode(".",$filename )));//split之类的都可以
最早以前判断都是判断strpos取得最后一个.的所在位置,现在都用strrchr了,毕竟它可以安全的操作二进制文件。

还可以通过finfo::file($filename);来取得文件的类型,然后再进行处理,不过。这已经不算是取文件名了。

大至是以上三种,其他一些方法类似的就不一一列出了

恭喜一下,phpmyadmin出了3.0测试版

恭喜一下,phpmyadmin出了3.0测试版

看新闻的时候,突然看到phpmyadmin出了3.0beta版本,只是好象新版本是基于5.2开发的。源码地址为:http://internap.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.0.0-beta-all-languages.zip,大家可以去下载,如果不能下载,可以先到:http://sourceforge.net/projects/phpmyadmin/,找到3.0beta版进行下载。

对于使用PHP进行开发的人员来说,phpmyadmin可以说是最常用的工具之一。其重要性不亚于一个好的IDE所带来的功效。

SF上面如此提示:

Welcome to the beta release of phpMyAdmin 3.0.0. This version supports various features of MySQL 5.1, the Maria and PBXT storage engines and
SweKey hardware authentication. The 3.0 series requires PHP 5.2+ and MySQL 5.0+.

看到cnbeta上有人评价说:phpmyadmin不是利器,而是神器。心中亦有此感啊。

下载源码,学习一下。oh yeah

smarty中的注释

smarty中的注释

写代码的时候不可避免的会使用到注释。大多数的情况下,我们都是使用<!-- 这里是注释 -->,因为这是HTML自带的注释功能,在这里的代码都不会被显示到浏览器。

然而,使用了smarty之类,我们确实不是很建议这样使用,因为,在<!---->标记里的smarty代码其实还是被解析了,如果是这样的话,那么,我们其实是多做了很多事情,却没有被显示出来,那就是说,我们其实多做了很多无用功。

因此,我们在使用smarty模版的时候,应该根据smarty的规范来。让我们看看手册怎么说:


所有例子中,我们假定你使用缺省的分隔符。Smarty中,所有在分隔符之外的内容被显示为静态内容,或者说不会被改变。一旦Smarty遇见分隔符,它将尝试解释它们,然后在其位置处显示合适的内容。

注释

模板注释由星号包围,继而由分隔符包围,型如:{* 这是一个注释 *}。Smarty注释不会在最终模板的输出中显示,这点和<!-- HTML comments -->不同。前者对于在模板中插入内部注释有用,因为没有人能看到。;-)

{* 这是Smarty注释,不出现在编译后的输出中 *}
<html>
<head>
<title>{$title}</title>
</head>
<body>

{* 另一个单行Smarty注释 *}
<!-- HTML注释将发送到浏览器 -->

{* 这是一个多行
Smarty注释
并不发送到浏览器
*}

{*********************************************************
多行注释块,包含了版权信息
@ author: bg@example.com
@ maintainer: support@example.com
@ para: var that sets block style
@ css: the style output
**********************************************************}

{* 包含了主LOGO和其他东西的头文件 *}
{include file='header.tpl'}


{* 开发注解:$includeFile变量在foo.php脚本中赋值 *}
<!-- 显示主内容块 -->
{include file=$includeFile}

{* 该<select>块是多余的 *}
{*
<select name="company">
{html_options options=$vals selected=$selected_id}
</select>
*}

{* 模板的cvs标记。下面的36应该是美元符号。
但是在CVS中被转换了。 *}
{* &#36;Id: Exp &#36; *}
{* $Id: *}
</body>
</html>
smarty中的变量使用

smarty中的变量使用

smarty中的变量和平时使用有点区别,比如$aa.bb其实代表的是$aa['bb'],具体如何个使用法,其实在手册里已经有详细说明了

Smarty可以识别嵌入在双引号中赋值的变量,只要变量名只包含数字,字母,下划线和方括号[](参见命名)。如果有其它字符(如句点,对象引用等),变量必须由反引号对`backticks`包含。你不可以嵌入修饰符,它们必须永远在引号之外使用。

实际使用中应该是这样的:

语法例子:
{func var="test $foo test"} <-- 使用$foo
{func var="test $foo_bar test"} <-- 使用$foo_bar
{func var="test $foo[0] test"} <-- 使用$foo[0]
{func var="test $foo[bar] test"} <-- 使用$foo[bar]
{func var="test $foo.bar test"} <-- 使用$foo(不是$foo.bar)
{func var="test `$foo.bar` test"} <-- 使用$foo.bar

{func var="test `$foo.bar` test"|escape} <-- 修饰符在引号外!

实际例子:
{include file="subdir/$tpl_name.tpl"} <-- 将以实际值替换$tpl_name
{cycle values="one,two,`$smarty.config.myval`"} <-- 必须有反引号!

看清楚哦。平时在使用的时候应该是感觉不出问题的,只有用在函数、循环里面,这才会成为使用中的问题。