Latest Entries »

Ajax缓存解决办法

转载一篇文章,在做聊天室的过程中困惑我很久的一个问题.呵呵,太感谢作者了.原文如下:

项目有时要用一些Ajax的效果,因为比较简单,也就没有去用什么Ajax.net之类的东西,手写代码也就实现了。、

第二天,有人向我报告错误;说是只有第一次读取的值正常,后面的值都不正常;我调试了一下 ,确实有这样的问题,查出是因为AJAX缓存的问题:解决办法有如下几种:

1、在服务端加 header(“Cache-Control: no-cache, must-revalidate”);(如php中)

2、在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″);

3、在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“Cache-Control”,”no-cache”);

4、在 Ajax 的 URL 参数后加上 “?fresh=” + Math.random(); //当然这里参数 fresh 可以任意取了

5、第五种方法和第四种类似,在 URL 参数后加上 “?timestamp=” + new Date().getTime();

6、用POST替代GET:不推荐

1、加个随机数
xmlHttp.open(“GET”, “ajax.asp?now=” + new Date().getTime(), true);

2、在要异步获取的asp页面中写一段禁止缓存的代码:
Response.Buffer =True
Response.ExpiresAbsolute =Now() – 1
Response.Expires=0
Response.CacheControl=”no-cache”

3、在ajax发送请求前加上xmlHTTP.setRequestHeader(“If-Modified-Since”,”0″);可以禁止缓存
xmlHTTP.open(“get”, URL, true);
xmlHTTP.onreadystatechange = callHTML;
xmlHTTP.setRequestHeader(“If-Modified-Since”,”0″);
xmlHTTP.send();

另一个作者写到:

AJAX的缓存是由浏览器维持的,对于发向服务器的某个url,ajax仅在第一次请求时与服务器交互信息,之后的请求中,ajax不再向服务器提交请求,而是直接从缓存中提取数据。

有些情况下,我们需要每一次都从服务器得到更新后数据。思路是让每次请求的url都不同,而又不影响正常应用:在url之后加入随机内容。
e.g.
url=url+”&”+Math.random();

Key points:
1.每次请求的url都不一样(ajax的缓存便不起作用)
2.不影响正常应用(最基本的)

—————-
方法二:(未经证实)
在JSP中禁止缓存
response.addHeader(“Cache-Control”, “no-cache”);
response.addHeader(“Expires”, “Thu, 01 Jan 1970 00:00:01 GMT”);

HTTP:
<META HTTP-EQUIV=”pragma” CONTENT=”no-cache”>
<META HTTP-EQUIV=”Cache-Control” CONTENT=”no-cache, must-revalidate”>
<META HTTP-EQUIV=”expires” CONTENT=”Wed, 26 Feb 1997 08:21:57 GMT”>
<META HTTP-EQUIV=”expires” CONTENT=”0″>

另一个作者写到:

我们都知道,ajax能 提高页面载入的速度的主要原因是通过ajax减少了重复数据的载入,真正做到按需获取,既然如此,我们在写ajax程序的时候不妨送佛送到西,在客户端再 做一次缓存,进一步提高数据载入速度。那就是在载入数据的同时将数据缓存在浏览器内存中,一旦数据被载入,只要页面未刷新,该数据就永远的缓存在内存中, 当用户再次查看该数据时,则不需要从服务器上去获取数据,极大的降低了服务器的负载和提高了用户的体验。

php 随机密码生成函数

<?php
mt_srand((double) microtime() * 1000000);
function gen_random_password($password_length = 32, $generated_password = ""){
$valid_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$chars_length = strlen($valid_characters) - 1;
for($i = $password_length; $i--; ) {
//$generated_password .= $valid_characters[mt_rand(0, $chars_length)];
$generated_password .= substr($valid_characters, (mt_rand()%(strlen($valid_characters))), 1);
}
return $generated_password;
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>php 密码生成器 v 4.0</title>
<style type="text/css">
body {
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<span style="font-weight: bold; font-size: 15pt;">密码生成器v4.0 by freemouse</span><br /><br />
<?php
if (isset($_GET['password_length'])){
if(preg_match("/([0-9]{1,8})/", $_GET['password_length'])){
print("密码生成成功:<br />
<span style=\"font-weight: bold\">" . gen_random_password($_GET['password_length']) . "</span><br /><br />\n");
} else {
print("密码长度不正确!<br /><br />\n");
}
}
print <<< end
请为密码生成其指定生成密码的长度:<br /><br />
<form action="{$_SERVER['PHP_SELF']}" method="get">
<input type="text" name="password_length">
<input type="submit" value="生成">
</form>
end;
?>
</body>
</html>

与 UNIX 构建系统交互: config.m4

扩展的 config.m4 文件告诉 UNIX 构建系统哪些扩展 configure 选项是支持的,你需要哪些扩展库,以及哪些源文件要编译成它的一部分。对所有经常使用的 autoconf 宏,包括 PHP 特定的及 autoconf 内建的,请查看 Zend Engine 2 API 参考 章节。

Tip当开发 PHP 扩展时,强烈建议安装 autoconf 2.13 版,尽管用更新的版本可使用。2.13 版被认为是在 autoconf 中可用性,适用性及用户基础等方面最好的版本。使用最新版本有时会与所期望的 configure 输出在样式上有所不同。

Example #1 config.m4 文件举例

dnl $Id$
dnl config.m4 for extension example
PHP_ARG_WITH(example, for example support,
[  --with-example[=FILE]       Include example support. File is the optional path to example-config])
PHP_ARG_ENABLE(example-debug, whether to enable debugging support in example,
[  --enable-example-debug        example: Enable debugging support in example], no, no)
PHP_ARG_WITH(example-extra, for extra libraries for example,
[  --with-example-extra=DIR      example: Location of extra libraries for example], no, no)

dnl 检测扩展是否已启用
if test "$PHP_EXAMPLE" != "no"; then

  dnl 检测 example-config。首先尝试所给出的路径,然后在 $PATH 中寻找
  AC_MSG_CHECKING([for example-config])
  EXAMPLE_CONFIG="example-config"
  if test "$PHP_EXAMPLE" != "yes"; then
    EXAMPLE_PATH=$PHP_EXAMPLE
  else
    EXAMPLE_PATH=`$php_shtool path $EXAMPLE_CONFIG`
  fi

  dnl 如果找到可用的 example-config,就使用它
  if test -f "$EXAMPLE_PATH" && test -x "$EXAMPLE_PATH" && $EXAMPLE_PATH --version > /dev/null 2>&1; then
    AC_MSG_RESULT([$EXAMPLE_PATH])
    EXAMPLE_LIB_NAME=`$EXAMPLE_PATH --libname`
    EXAMPLE_INCDIRS=`$EXAMPLE_PATH --incdirs`
    EXAMPLE_LIBS=`$EXAMPLE_PATH --libs`

    dnl 检测扩展库是否工作正常
    PHP_CHECK_LIBRARY($EXAMPLE_LIB_NAME, example_critical_function,
    [
      dnl 添加所需的 include 目录
      PHP_EVAL_INCLINE($EXAMPLE_INCDIRS)
      dnl 添加所需的扩展库及扩展库所在目录
      PHP_EVAL_LIBLINE($EXAMPLE_LIBS, EXAMPLE_SHARED_LIBADD)
    ],[
      dnl 跳出
      AC_MSG_ERROR([example library not found. Check config.log for more information.])
    ],[$EXAMPLE_LIBS]
    )
  else
    dnl 没有可用的 example-config,跳出
    AC_MSG_RESULT([not found])
    AC_MSG_ERROR([Please check your example installation.])
  fi

  dnl 检测是否启用调试
  if test "$PHP_EXAMPLE_DEBUG" != "no"; then
    dnl 是,则设置 C 语言宏指令
    AC_DEFINE(USE_EXAMPLE_DEBUG,1,[Include debugging support in example])
  fi

  dnl 检测额外的支持
  if test "$PHP_EXAMPLE_EXTRA" != "no"; then
    if test "$PHP_EXAMPLE_EXTRA" == "yes"; then
      AC_MSG_ERROR([You must specify a path when using --with-example-extra])
    fi

    PHP_CHECK_LIBRARY(example-extra, example_critical_extra_function,
    [
      dnl 添加所需路径
      PHP_ADD_INCLUDE($PHP_EXAMPLE_EXTRA/include)
      PHP_ADD_LIBRARY_WITH_PATH(example-extra, $PHP_EXAMPLE_EXTRA/lib, EXAMPLE_SHARED_LIBADD)
      AC_DEFINE(HAVE_EXAMPLEEXTRALIB,1,[Whether example-extra support is present and requested])
      EXAMPLE_SOURCES="$EXAMPLE_SOURCES example_extra.c"
    ],[
      AC_MSG_ERROR([example-extra lib not found. See config.log for more information.])
    ],[-L$PHP_EXAMPLE_EXTRA/lib]
    )
  fi

  dnl 最后,将扩展及其所需文件等信息传给构建系统
  PHP_NEW_EXTENSION(example, example.c $EXAMPLE_SOURCES, $ext_shared)
  PHP_SUBST(EXAMPLE_SHARED_LIBADD)
fi

autoconf 语法简介

config.m4 文件使用 GNU autoconf 语法编写。简而言之,就是用强大的宏语言增强的 shell 脚本。注释用字符串 dnl 分隔,字符串则放在左右方括号中间(例如,[])。字符串可按需要多次嵌套引用。完整的语法参考可参见位于 » http://www.gnu.org/software/autoconf/manual/autoconf 手册。

PHP_ARG_*: 赋予用户可选项

在以上的 config.m4 例子中,两条注释后,最先见到的 3 行代码,使用了 PHP_ARG_WITH()PHP_ARG_ENABLE()。这些给 configure 提供了可选项,和在运行 ./configure –help 时显示的帮助文本。就象名称所暗示的,其两者的不同点在于是创建 –with-* 选项还是 –enable-* 选项。每个扩展应提供至少一个以上的选项以及扩展名称,以便用户可选择是否将扩展构建至 PHP 中。按惯例,PHP_ARG_WITH() 用于取得参数的选项,例如扩展所需库或程序的位置;而 PHP_ARG_ENABLE() 用于代表简单标志的选项。

Example #2 configure 输出举例

$ ./configure --help
...
  --with-example[=FILE]       Include example support. FILE is the optional path to example-config
  --enable-example-debug        example: Enable debugging support in example
  --with-example-extra=DIR      example: Location of extra libraries for example
...

$ ./configure --with-example=/some/library/path/example-config --disable-example-debug --with-example-extra=/another/library/path
...
checking for example support... yes
checking whether to enable debugging support in example... no
checking for extra libraries for example... /another/library/path
...

Note:

在调用 configure 时,不管选项在命令行中的顺序如何,都会按在 config.m4 中指定的顺序进行检测。

处理用户选择

config.m4 可给用户提供一些做什么的选择,现在就是做出选择的时候了。在上例中,三个选项在未指定时显然默认为 “no”。习惯上,最好用此值作为用于启用扩展的选项的默认值,为了扩展与 PHP 分开构建则用 phpize 覆盖此值,而要构建在 PHP 中时则不应被默认值将扩展空间弄乱。处理这三个选项的代码要复杂得多。

处理 –with-example[=FILE] 选项

首先检测是否设置了 –with-example[=FILE] 选项。如此选项未被指定,或使用否定的格式(–without-example ),或赋值为 “no” 时,它会控制整个扩展的含有物其他任何事情都不会发生。在上面的例子中所指定的值为 /some/library/path/example-config,所以第一个 test 成功了。

接下来,代码调用 AC_MSG_CHECKING(),这是一个 autoconf 宏,输出一行标准的如 “checking for …” 的信息,并检测用户假定的 example-config 是否是一个明确的路径。在这个例子中,PHP_EXAMPLE 所取到的值为 /some/library/path/example-config,现已复制到 EXAMPLE_PATH 变量中了。只有用户指定了 –with-example ,才会执行代码 $php_shtool path $EXAMPLE_CONFIG,尝试使用用户当前的 PATH 环境变量推测 example-config 的位置。无论如何,下一步都是检测所选的 EXAMPLE_PATH 是否是正常文件,是否可执行,及是否执行成功。如成功,则调用 AC_MSG_RESULT(),结束由 AC_MSG_CHECKING() 开始的输出行。否则,调用 AC_MSG_ERROR(),打印所给的信息并立即中断执行 configure

代码现在执行几次 example-config 以确定一些站点特定的配置信息。下一步调用的是 PHP_CHECK_LIBRARY(),这是 PHP 构建系统提供的一个宏,包装了 autoconfAC_CHECK_LIB() 函数。PHP_CHECK_LIBRARY() 尝试编译、链接和执行程序,在第一个参数指定的库中调用由第二个参数指定的符号,使用第五个参数给出的字符串作为额外的链接选项。如果尝试成功了,则运行第三个参数所给出的脚本。此脚本从 example-config 所提供的原始的选项字符串中取出头文件路径、库文件路径和库名称,告诉 PHP 构建系统。如果尝试失败,脚本则运行第四个参数中的脚本。此时调用 AC_MSG_ERROR() 来中断程序执行。

处理 –enable-example-debug 选项

处理 –enable-example-debug 很简单。只简单地检测其真实值。如果检测成功,则调用 AC_DEFINE() 使 C 语言宏指令 USE_EXAMPLE_DEBUG 可用于扩展的源代码。第三个参数是给 config.h 的注释字符串,通常可放心的留空。

处理 –with-example-extra=DIR 选项

对于此例子来说,由 –with-example-extra=DIR 选项所请求的假定的“额外”功能操作不会与假定的 example-config 程序共享,也没有默认的搜索路径。因此,用户需要在所需的库之前提供设置程序。有点不象现实中的扩展,在这里的设置仅仅起说明性的作用。

代码开始用已熟知的方式来检测 PHP_EXAMPLE_EXTRA 的真实值。如果所提供的为否定形式,则不会进行其他处理,用户也不会请求额外的功能。如果所提供的为未提供参数的肯定形式,则调用 AC_MSG_ERROR() 中止处理。下一步则再次调用 PHP_CHECK_LIBRARY()。这一次,因为没有提供预定义编译选项,PHP_ADD_INCLUDE()PHP_ADD_LIBRARY_WITH_PATH() 用于构建额外功能所需的头文件路径、库文件路径和库标志。也调用 AC_DEFINE() 来指示所请求的额外功能代码是可用的,设置变量来告诉以后的代码,有额外的源代码要构建。如果检测失败,则调用所熟悉的 AC_MSG_ERROR()。另一种不同的处理失败的方式是更换为调用 AC_MSG_WARNING(),例如:

AC_MSG_WARNING([example-extra lib not found. example will be built without extra functionality.])

上例中,configure 会打印一段警告信息而不是错误,且继续处理。用哪种方式处理失败留给扩展开发人员在设计时决定。

告诉构建系统要做什么

有了所需的头文件和特定的库,有了全部选项处理代码及宏定义,还有一件事要做:必须告诉构建系统去构建扩展本身和被其用到的文件。为了做这些,则要调用 PHP_NEW_EXTENSION() 宏。第一个参数是扩展的名称,和包含它的目录同名。第二个参数是做为扩展的一部分的所有源文件的列表。参见 PHP_ADD_BUILD_DIR() 以获取将在子目录中源文件添加到构建过程的相关信息。第三个参数总是 $ext_shared, 当为了 –with-example[=FILE] 而调用 PHP_ARG_WITH()时,由 configure 决定参数的值。第四个参数指定一个“SAPI 类”,仅用于专门需要 CGI 或 CLI SAPI 的扩展。其他情况下应留空。第五个参数指定了构建时要加入 CFLAGS 的标志列表。第六个参数是一个布尔值,为 “yes” 时会强迫整个扩展使用 $CXX 代替 $CC 来构建。第三个以后的所有参数都是可选的。最后,调用 PHP_SUBST() 来启用扩展的共享构建。参见 扩展相关 FAQ 以获取更多有关禁用共享方式下构建扩展的信息。

counter 扩展的 config.m4 文件

以前编写的 counter 扩展有一个比上面所述更简单的 config.m4 文件,它不使用很多构建系统的特性。对不使用外部的或绑定的库的扩展来说,这是一个比较好的操作方式。

Example #3 counter 的 config.m4 文件

dnl
$
Id$
dnl config.m4 for extension counter

PHP_ARG_ENABLE(counter, for counter support,
[  --enable-counter            Include counter support])

dnl Check whether the extension is enabled at all
if test "$PHP_COUNTER" != "no"; then
  dnl Finally, tell the build system about the extension and what files are needed
  PHP_NEW_EXTENSION(counter, counter.c counter_util.c, $ext_shared)
  PHP_SUBST(COUNTER_SHARED_LIBADD)
fi



If you try to install 5.3.6 on by patching sources you will most likely see a lot of error messages similar to the following:

$ ./configure
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
./configure: 490: 5: Bad file descriptor
./configure: 490: :: checking for pthreads_cflags: not found
./configure: 490: 6: Bad file descriptor
./configure: 490: checking for pthreads_cflags… : not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 490: ac_fn_c_try_run: not found
./configure: 492: 5: Bad file descriptor
./configure: 492: :: result: : not found
./configure: 492: 6: Bad file descriptor
./configure: 492: : Permission denied
./configure: 495: 5: Bad file descriptor
./configure: 495: :: checking for pthreads_lib: not found
./configure: 495: 6: Bad file descriptor
./configure: 495: checking for pthreads_lib… : not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
cat: confdefs.h: No such file or directory
./configure: 555: ac_fn_c_try_run: not found
./configure: 557: 5: Bad file descriptor
./configure: 557: :: result: : not found
./configure: 557: 6: Bad file descriptor
./configure: 557: : Permission denied
./configure: 633: 5: Bad file descriptor
./configure: 633: :: result: : not found
./configure: 633: 6: Bad file descriptor
./configure: 633: : Permission denied
./configure: 635: 5: Bad file descriptor
./configure: 635: :: result: Configuring SAPI modules: not found
./configure: 635: 6: Bad file descriptor
./configure: 635: Configuring SAPI modules: not found
./configure: 666: 5: Bad file descriptor

See what happened when using buildconf earlier..

$ ./buildconf –force
Forcing buildconf
buildconf: checking installation…
buildconf: autoconf version 2.64 (ok)
buildconf: Your version of autoconf likely contains buggy cache code.
Running vcsclean for you.
To avoid this, install autoconf-2.13.
Can’t figure out your VCS, not cleaning.

This is not a regular warning and it cannot be neglected. You have to use autoconf-2.13. This is because the newer version of autoconf cannot process scripts which are meant for autoconf 2.13. So just install autoconf-2.13 and then do the compilation again..

sudo apt-get install autoconf2.13

Also if you have a low memory machine, then you might get error such as:

[lots of compile output]

/bin/sh /home/ibb_admin/temp/php-5.3.0/libtool –silent –preserve-dup-deps –mode=compile gcc -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic -Iext/fileinfo/ -I/home/ibb_admin/temp/php-5.3.0/ext/fileinfo/ -DPHP_ATOM_INC -I/home/ibb_admin/temp/php-5.3.0/include -I/home/ibb_admin/temp/php-5.3.0/main -I/home/ibb_admin/temp/php-5.3.0 -I/home/ibb_admin/temp/php-5.3.0/ext/date/lib -I/home/ibb_admin/temp/php-5.3.0/ext/ereg/regex -I/usr/include/libxml2 -I/opt/include -I/opt/include/freetype2 -I/usr/include/imap -I/usr/kerberos/include -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/oniguruma -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl -I/home/ibb_admin/temp/php-5.3.0/ext/mbstring/libmbfl/mbfl -I/opt/include/mysql -I/usr/include/mysql -I/home/ibb_admin/temp/php-5.3.0/ext/sqlite3/libsqlite -I/home/ibb_admin/temp/php-5.3.0/TSRM -I/home/ibb_admin/temp/php-5.3.0/Zend    -I/usr/include -g -O2  -c /home/ibb_admin/temp/php-5.3.0/ext/fileinfo/libmagic/apprentice.c -o ext/fileinfo/libmagic/apprentice.lo
virtual memory exhausted: Cannot allocate memory
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

So just upgrade the gcc compiler to its latest version and also add –disable-fileinfo to ./configure

Hence full installation procedure would be similar to:

sudo apt-get install autoconf2.13
wget http://us.php.net/get/php-5.3.6.tar.bz2/from/us.php.net/mirror
tar -xjf php-5.3.6.tar.bz2
cd php-5.3.6/
./buildconf –force
./configure –disable-fileinfo –enable-fpm –with-zlib –enable-pdo –with-pdo-mysql –enable-sockets –with-mysql –enable-calendar –with-iconv –enable-exif –enable-soap –enable-ftp –enable-wddx –with-zlib –with-bz2 –with-gettext –with-xmlrpc –enable-pcntl –enable-soap –enable-bcmath –enable-mbstring –enable-dba –with-openssl –with-mhash –with-mcrypt –with-xsl –with-curl –with-pcre-regex –with-gd –enable-gd-native-ttf –with-ldap –enable-pdo –with-pdo-mysql –with-mysql –with-sqlite –with-pdo-sqlite –enable-zip–enable-sqlite-utf8 –with-pear

Of course, your php configure options can be different.



问题:
cron计划任务,定义每五分钟运行一次,可是每运行一次就能收到cron发的邮件通知,这样会导致每天收到很多邮件

解决方法:
将运行结果定向到一个文件中去,比如,
echo “######” > aaa 就不会收到邮件了

Centos使用NTP自动同步系统时间

安装ntp服务
#yum install ntp (安前最好,先查看一下是否已经安装了rpm -ql ntp )

将本机默认时区设为上海
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

添加任务计划 (crontab -l 查看当前用户任务计划)
crontab -e
0-59/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org

同时建议修改一下 /etc/sysconfig/ntpd 文件
vim /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
(改成 yes BIOS 的时间也会跟着一起改变。)

asia.pool.ntp.org 亚洲的时间服务器,速度还可以,
到这里可以找到世界各地的时间服务器: http://www.pool.ntp.org/

隐藏Apache的版本

让我们着眼于2个参数,分别为ServerTokens和ServerSignature,通过控制这2个阀门应该就能起到一些作用,比如我们可以在配置文件中这么写:

ServerTokens ProductOnly
ServerSignature Off

ServerTokens
这个阀门用于控制服务器是否相应来自客户端的请求,向客户端输出服务器系统类型或内置模块等重要的系统信息。

* 在主配置文件中提供全局控制
* 默认阀值为”Full”(ServerTokens Full),所以,如果你的Linux发行版本没有更改过这个阀值的话,所有与你的系统有关的敏感信息都会向全世界公开(恐怖哦~)。比如RHEL会将该阀值更改为”ServerTokens OS”,而Debian依然使用默认的”Full”阀值

以apache-2.0.55为例,阀值可以设定为以下某项(后面为相对应的Banner Header):

ProductOnly >>> Server: Apache
Major >>> Server: Apache/2
Minor >>> Server: Apache/2.0
Minimal >>> Server: Apache/2.0.55
OS >>> Server: Apache/2.0.55 (Debian)
Full (or not specified) default >>> Server: Apache/2.0.55 (Debian) PHP/5.1.2-1
+b1 mod_ssl/2.0.55 OpenSSL/0.9.8b

ServerSignature
这个阀门控制由系统生成的页面(错误信息,mod_proxy ftp directory listing等等)的页脚中如何显示信息。

* 可在全局设置文件中控制,或是通过.htaccess文件控制
* 默认为”off “(ServerSignature Off),有些Linux发行版本可能会打开这个阀门,比如Debian在默认的虚拟主机上默认将这个阀门设置为开放
* 全局阀门的阀值会被虚拟主机或目录单位的配置文件中的阀值所覆盖,所以,必须确保这样的事情不应该发生

可用的阀值为下面所示:

Off (default): 不输出任何页脚信息 (如同Apache1.2以及更旧版本,用于迷惑)
On:输出一行关于版本号以及处于运行中的虚拟主机的ServerName
(2.0.44之后的版本,由ServerTokens负责是否输出版本号)
EMail: 创建一个发送给ServerAdmin的”mailto”

注意*上述关于如何设置2个阀门从而尽量减少敏感信息泄露的方法,并不会使你的服务器真的更安全,如果你现在使用的版本比较旧,请务必尽快将系统升级,降低被蠕虫攻击的风险。

php默认会输出header信息:
Date: Tue, 15 Apr 2008 13:58:46 GMT
Server: Apache/2.2.8
X-Powered-By: PHP/5.2.3
这样一下子php信息就全曝光了。怎样解决呢。

网上一搜中文,还真找不到相关信息。用英文一搜搜到了(下面是原文)

If you have read my previous tip, “Hide apache software version“, you have seen how you can configure apache to provide only a minimal amount of information about the installed software versions in its banner. But if you are using the PHP module in your web server (as most of us are), then there is one additional step that need to be completed, and this is what I will show you in this tip.

After implementing the apache directives ServerTokens and ServerSignature as shown in “Hide apache software version“, we test its functionality against a regular html file and we get the following response:

HEAD http://remote_server.com/index.html
200 OK
Connection: close
Date: Fri, 16 Jun 2006 01:13:23 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
Client-Date: Fri, 16 Jun 2006 21:42:53 GMT
Client-Peer: 192.168.0.102:80
Client-Response-Num: 1

This looks good. But if we do the same thing against an URL that is a PHP file:

HEAD http://remote_server.com/index.php 200 OK Connection: close Date: Fri, 16 Jun 2006 01:16:30 GMT Server: Apache Content-Type: text/html; charset=UTF-8 Client-Date: Fri, 16 Jun 2006 21:48:13 GMT Client-Peer: 192.168.0.102:80 Client-Response-Num: 1 X-Powered-By: PHP/5.1.2-1+b1

Ups… As we can see PHP adds its own banner:

X-Powered-By: PHP/5.1.2-1+b1…

Let’s see how we can disable it. In order to prevent PHP from exposing the fact that it is installed on the server, by adding its signature to the web server header we need to locate in php.ini the variable expose_php and turn it off.

By default expose_php is set to On.

In your php.ini (based on your Linux distribution this can be found in various places, like /etc/php.ini, /etc/php5/apache2/php.ini, etc.) locate the line containing “expose_php On” and set it to Off:

expose_php = Off

After making this change PHP will no longer add it’s signature to the web server header. Doing this, will not make your server more secure… it will just prevent remote hosts to easily see that you have PHP installed on the system and what version you are running.

结果简单的让人吃惊,只是需要修改php.ini 的 expose_php 把默认的 On改成 Off 就行了。

ERROR: unknown key name ‘UNIX_TIMESTAMP’ in /usr/local/etc/sphinx.conf line 575 col 24.

That line defines the query we use:

sql_query = \
SELECT id, idx_type, customer_id, website_page_id, title, \
UNIX_TIMESTAMP(date_added) AS date_added, \
url, content \
FROM main.pages

> SELECT id, idx_type, customer_id, website_page_id, title, \

Remove trailing spaces from this line.

Could be a bug in the config parser, maybe try writing the query on a single line without
using the “\” line breaks.

ssh 隧道建立:

ssh 隧道建立(本地内网mysql外部公网mysql同步):
ssh -L 127.0.0.1:3307:58.68.232.69:3306 -CfNg xxx.xxx.xxx.xxx
ssh -R 0.0.0.0:3307:localhost:3306 xxx.xxx.xxx.xxx -fN

Powered by WordPress | Theme: Motion by 85ideas.