Latest Entries »

也许很多朋友还没有遇到这个问题。可惜我碰到了。后来一直寻找解决的办法。目前,终于可以正常使用了。在此把配置的过程整理出来给大家参考一下。有需要的话就拿去用。
只是有点长,四五页只写mysql+vsftpd的配置过程。大家慢慢看吧。也欢迎提出疑问,如果有不合理的话,也希望能给予纠正。谢谢。

在安装系统分区时,强烈建议使用手动分区,这样做的目的是为了便于处理quota的问题。这里给个分区的建议:
/boot  100M
Swap  1024M   //很多资料都建议说是物理内存的两倍,所以,这个值可以根据各自的物理内存大小来设置
/      10240M  //这个分区一定要比所安装软件大小总和还要大,要不然不能正常安装系统,
/home  剩下的空间 //把所有的用户资料或内容都放在/home下,这样做的有一个好处是,如果系统崩溃,那么只要动用到/分区却可。

Vsftpd是目前在linux系统环境下表现最为优越的安全,稳定,快速的性能,加上Vsftpd的可读性强、易配置,受到更为广泛的应用。
Vsftpd有三种实现的形式,分别为:
1、  匿名用户形式:在默认安装的情况下,系统只提供匿名用户访问;
2、  本地用户形式:以/etc/passwd中的用户名为认证方式;
3、  虚拟用户形式:支持将用户名和口令保存在数据库文件或数据库服务器中。

相对于FTP的本地用户形式来说,虚拟用户只是FTP服务器的专有用户,虚拟用户只能访问FTP服务器所提供的资源,这大大增强系统本身的安全性。相对于匿名用户而言,虚拟用户需要用户名和密码才能获取FTP服务器中的文件,增加了对用户和下载的可管理性。对于需要提供下载服务,但又不让所有人匿名下载;既需要对下载用户进行管理,又考虑到主机安全和管理方便的FTP站点来说,虚拟用户是一种极好的解决方案。

下面将针对第三种Vsftpd的实现形式进行作详细的配置记录。

[[i] 本帖最后由 ankey 于 2007-11-28 09:16 编辑 [/i]]

ankey 2007-11-28 01:11
一:下载安装
在root目录下建个software,这样是为了把所有需要用到的软件都统一放在这里,方便管理。
Vsftp官方下载点:[url]ftp://vsftpd.beasts.org/users/cevans/vsftpd-2.0.4.tar.gz[/url] 目前最新版本已为2.05。
下载pam-mysql:[url]http://nchc.dl.sourceforge.net/sourceforge/pam-mysql/pam_mysql-0.5.tar.gz[/url] 最新版本已为0.7。

A. 开始安装vsftpd
# rpm -e vsftpd-**  //卸载原来低版本的vsftp
# cd /root/software/
# tar -zvxf vsftpd-2.0.4.tar.gz
# cd vsftpd-2.0.4
# make
把编译好的文件安装到相应目录下即可,没有相关目录请先创建。
# cp vsftpd /usr/local/sbin/vsftpd
# cp vsftpd.conf.5 /usr/local/man/man5/
# cp vsftpd.8 /usr/local/man/man8/
# cp vsftpd.conf /etc/

B. 启动mysqld服务
Mysqld可以直接使用系统自带的,只要启动起来即可。如下:
# service mysqld start/stop/restart  //启动/停止/重启mysqld
# chkconfig mysqld on           //设置为系统服务,跟随系统自动启动。

C. 安装Pam-mysql
由于是基于mysql的pam认证的虚拟用户配置,所以需要安装pam-mysql,系统默认无些服务,系统安装包里也无此软件,需要另外下载就是上述下载的安装包。
# cd /root/software/
# tar –zvxf pam_mysql-0.5.tar.gz
# cd pam_mysql
# make
# cp pam_mysql.so /lib/security

 

ankey 2007-11-28 01:12
二:服务配置

1.Vsftpd配置
配置vsftpd.conf,增加对每个虚拟用户的配置,并对每个虚拟用户详细权限进行配置。
创建/etc/vsftpd_user_conf目录,并在其下分别为虚拟用户test,test1,test2增加test,test1,test2三个配置文件。
# mkdir /etc/vsftpd_user_conf
# cd /etc/vsftpd_user_conf
# touch test test1 test2
#test,test1,test2配置文件根据需要设置相关vsftp的权限,比如test用户可以下载上传,修改,test文件内容如下:
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_world_readable_only=NO  //可以浏览和下载有相关权限的文件(其他用户有可读和可执行权限)
local_root=/home/virtual/test     //锁定在相应的目录下,以防越权访问

主配置文件vsftpd.conf内容如下:
listen=YES                     //打开端口监听21
anonymous_enable=NO     //关闭匿名用户权限
local_enable=YES        //一定要yes,否则ftp登入会提示,本地用户和匿名用户都没有访问权限的提示
write_enable=NO               
anon_upload_enable=NO
anon_mkdir_write_enable=NO
anon_other_write_enable=NO     //在主配置中关闭所有的读写改权限。
guest_enable=YES
guest_username=virtual        //这两行的意思是采用虚拟用户形式
virtual_use_local_privs=YES   //虚拟用户和本地用户权限相同

user_config_dir=/etc/vsftpd_user_conf  //增加对每个虚拟用户的配置

anon_world_readable_only=YES  //不可以浏览和下载有相关权限的文件(其他用户有可读和可执行权限)
connect_from_port_20=YES
hide_ids=YES
pasv_min_port=50000
pasv_max_port=60000
dirmessage_enable=YES
xferlog_enable=YES   
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
xferlog_enable=YES
ls_recurse_enable=NO
ascii_download_enable=NO
async_abor_enable=YES
ftpd_banner=Welcome to lanmang.com FTP service.
one_process_model=YES
idle_session_timeout=120
data_connection_timeout=300
accept_timeout=60
connect_timeout=60
anon_max_rate=50000
max_clients=200
max_per_ip=4
check_shell=NO

2.虚拟用户配置
A.创建真实用户与虚拟用户的映射
# useradd virtual
# passwd virtual     //提示输入密码时请输123456
#必要时使用 : useradd -d /home/ftpsite -s /sbin/nologin virtual

B.创建数据库
# mysql –u root –p
Mysql>create database ftpd;
Mysql> use ftpd;
Mysql> create table user(name char(20) binary,passwd char(20) binary);
Mysql> insert into user (name,passwd) values (‘test’,'password’);
Mysql> insert into user (name,passwd) values (‘test1′,’password1′);
Mysql> insert into user (name,passwd) values (‘test2′,’password2′);
Mysql> grant select on ftpd.user to virtual@localhost identified by ’123456′;
Mysql>quit

A. 建立认证文件
# cd /etc/pam.d/
# touch ftp   //如果有就不用生成了。
# vi ftp      //内容如下:
auth required /lib/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpd table=user usercolumn=name passwdcolumn=passwd crypt=0
account required /lib/security/pam_mysql.so user=virtual passwd=123456 host=localhost db=ftpd table=user usercolumn=name passwdcolumn=passwd crypt=0

# 注意:
#crypt=0: 明文密码
#crypt=1: 使用crpyt()函数(对应SQL数据里的encrypt(),encrypt()随机产生salt)
#crypt=2: 使用MYSQL中的password()函数加密
#crypt=3:表示使用md5的散列方式#上面是两句配置,第一句是以auth开始的,第二句以account开始的。

 

ankey 2007-11-28 01:13
三:启动/关闭vsftpd服务
# /usr/local/sbin/vsftpd &
# vi /etc/rc.d/rc.local           //修改系统启动文件,在最后加入/usr/local/sbin/vsftpd & 作为系统服务,将会随着系统而启动。
#注:关闭服务为:killall vsftpd
#查看是否启动成功请使用netstat –ntl查看21端口是否起来。

四:配额设置
对用户做磁盘限额,限额功能是系统自带,不是vsftp功能!
对virtual用户主目录:/home/ftpsite/限制,修改/etc/fstab文件,重新启动计算机
A.编辑/etc/fstab文件,重新启动计算机,使限额功能生效
     # vi /etc/fstab
    把
LABEL=/home   /home   ext3    defaults     1 2
修改为:
LABEL=/home   /home   ext3    defaults,usrquota,grpquota     1 2
# reboot
    启动完成后:
    # cd /home
        # quotacheck –avug
        # quotaon -a
B.限额配置文件的修改
# edquota virtual //为用户virtual设置磁盘配额
          系统会自动打开配额文件,如下:
          Disk quotas for user virtual (uid 502):
          Filesystem         blocks       soft       hard     inodes     soft     hard
           /dev/sda2           424          0          0         13        0        0
#注:
#第一列是启用了配额的文件系统的名称。第二列显示了用户当前使用的块数,单位为KB。随后的两列用来设置用户在该文件系统上的软硬块限度。
inodes 列显示了用户当前使用的i节点数量。最后两列用来设置用户在该文件系统上的软硬i节点限度.硬限是用户或组群可以使用的磁盘空间的 绝对最大值。达到了该限度后,磁盘空间就不能再被用户或组群使用了。软限定义可被使用的最大磁盘空间量。和硬限不同的是,软限可以在一段时期内被超过。这段时期被称为过渡期(grace period),默认七天的超越。过渡期可以用秒钟、分钟、小时、天数、周数、或月数表示。如果以上值中的任何一个被设置为 0,那个限度就不会被设置。
C.要校验用户的配额是否被设置,我们可以使用以下命令:
# quota virtual
用以下命令显示磁盘配额使用状态:# repquota  -a

 

ankey 2007-11-28 01:13
一篇完整的vsftpd+mysql配置文档暂告一段落。
下面写一下,新添加用户的方法。
# mysql -u root -h localhost –p
mysql> use ftpd;
mysql> insert into user (name,passwd) values (‘test’,'password’);
mysql> quit
# cd /etc/vsftpd_user_conf
# touch test
# vi test
write_enable=YES
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_world_readable_only=NO
local_root=/home/virtual/test

# cd /home/virtual/
# mkdir test
# chown virtual:virtual test
chmod 700 test

CentOS Apache配置详解

要想在linux上实现网页服务器(www)需要Apache这个服务器软件,不过Apache仅能提供最基本的静态网站数据而已,想要实现动态网站的话,最好还是要PHP与MySQL的支持,所以下面我们将会以LAMP(linux+Apache+MySQL+PHP)作为安装与设置的介绍。

LAMP所需软件与其结构
httpd mysql mysql-Server php php-devel php-mysql
可以用rpm包安装,或者直接用yum安装
#yum install httpd mysql-server php php-devel php-mysql
先来了解一下apache 2.0这个版本的相关结构,这样才能知道如何处理我们的网页数据
/etc/httpd/conf/httpd.conf:最主要的配置文件,不过很多其他的distribution都将这个文件拆成数个小文件,分别管理不同的参数。但是最主要配置文件还是以这个文件名为主。
/etc/httpd/conf.d/*.conf:这个事CentOS的特色之一,如果你不想修改原始配置文件httpd.conf的话,那么可以将你自己的额外参数独立出来,而启动apache时,这个文件就会被读入到主要配置文件。
/usr/lib/httpd/modules:apache支持很多的模块,所以您想要使用的模块默认都放置在此目录
/var/www/html:这里是CentOS默认的“首页”所在目录。
/var/www/error:如果因为主机设置错误,或者是浏览器端要求的数据错误,在浏览器上出现的错误信息就已这个目录的默认信息为主。
/var/www/icons:提供apache的一些小图标
/var/www/cgi-bin :默认给一些可执行的CGI程序放置的目录
/var/log/httpd:默认apache的日志文件都放在这里,对于流量大的网站来说,这个目录要很小心,因为这个文件很容易变的很大,您需要足够的空间哦
/usr/sbin/apachectl:这是Apache的主要执行文件,这个执行文件其实是shell script,它可以主动检测系统上的一些设置值,好让您启动Apache时更简单
/usr/sbin/httpd:这是主要的apache的二进制文件
/usr/bin/htpasswd:当您想登陆某些网页时,需要输入账号与密码。那么Apache本身就提供一个最基本的密码保护方式。该密码的产生就是通过这个命令实现的

至于MySQL方面,您需要知道的几个重要目录与文件有以下几个:
/etc/my.cnf:这是Mysql的配置文件,包括您想要进行mysql数据库的最佳化,或者是正对mysql进行一些额外的参数指定,都可以在这个文件里实现
/usr/lib/mysql:这个目录是MySQL数据库放置的位置,当启动任何MySQL的服务器时,请务必记得在备份时,将此目录完整的备份下来。

另外,在PHP方面,应该了解以下几个文件。
/usr/lib/httpd/modules/libphp4.so:PHP提供给apache使用的模块,这个关系我们能否在apache网页上面设计php程序语言的最重要文件
/etc/httpd/conf.d/php.conf:你要不要手动将该模块写入Httpd.conf中呢?不需要,因为系统已经主动将php设置参数写入到这个文件中了,而这个文件会在apache重新启动时被读入。
/etc/php.ini:这是PHP的主要配置文件,包括PHP能不能允许用户上传文件,能不能允许某些低安全性的标志等,都在这个配置文件中设置。
/etc/php.d/mysql.ini /usr/lib/php4/mysql.so:PHP能否可以支持MySQL接口就看这两个文件了。这两个文件是由php-mysql软件提供的
/usr/bin/phpize /usr/include/php:如果您以后想要安装类似PHP加速器可以让浏览速度加快的话,那么这个文件与目录就需要存在,否则加速器软件没法用。

httpd.conf的基本设置
首先,你需要在/etc/hosts内需要有个一个完整的主机名,否则在重启apache服务时,会提示找不到完整的主机名。
httpd.conf的基本设置是这样的:
<设置项目>
      次设置项目内的相关参数
      。。。。
</设置项目>
例如,你想要针对首页/var/www/html提供额外的功能,那么可以进行如下设置:
<Directory “/var/www/html”>
   Options Indexes
   ……
</Directory>

针对主机环境的设置项目
#vi /etc/httpd/conf/httpd.conf
ServerTokens OS
# 这个项目在告诉客户端WWW服务器的版本和操作系统,不需要改编它
#如果你不想告诉太多的主机信息,将这个项目的OS改成Minor

ServerRoot “/etc/httpd”
#这个是设置文件的最顶层目录,通常使用绝对路径,下面某些数据设置使用相对路径时
#就是与这个目录设置值有关的下层目录,不需要更改它
ServerRoot
设定Apache 安装的绝对路径
TimeOut
设定 服务器接收至完成的最长等待时间
KeepAlive
设定服务器是否开启连续请求功能,真实服务器一般都要开启
Port
设定http服务的默认端口。
User/Group
设定 服务器程序的执行者与属组,这个一般是apache

下面我们就针对Apache做几个实验
1:我们测试把默认网站目录改到root家目录下
新建/root/website目录
#mkdir -p /root/website
#echo “website page” >> /root/website/index.html
#vi /etc/httpd/conf/httpd.conf
找到 DocumentRoot “/var/www/html” 这一段   //apache的根目录
把/var/www/html 这个目录改到 /root/website
在找到 <Directory “/var/www/html”> //定义apache /var/www/html这个区域
把 /var/www/html改成/root/website
这样我们就把apahce的默认路径改掉了
然后重启服务
#service httpd restart  
//这里在你重启服务的时候,可能会报错,说找不到目录,这个主要是由于selinux导致的
那怎么解决呢?有2个办法,关掉selinux  
#setenforce 0
或者更改/root/website这个文件的selinux属性,让它匹配httpd这个服务器的要求
怎么改?我们可以复制/var/www/html这个目录的selinux属性
#chcon -R –reference /var/www/html /root/website
然后在重启服务,之后你就看到它没有报错了
不过你去访问localhost的时候,会发现访问拒绝 这是为什么呢?主要是因为你的/root的权限是750,ahache这个用户没有权限访问,你需要更改掉权限,可以这样改
#chmod -R 755 /root
然后去访问 发现正常了

2:基于名称的虚拟主机
需要两个域名解析到你的服务器,对应关系是
/var/www/server             server.example.com
/var/www/client                client.example.com
当访问这两个域名时,可以分别显示出不同文件里面主页的内容
#echo “server page” >> /var/www/server/index.html
#echo “client page” >> /var/www/client/index.html
然后我们编辑一个配置文件
#vi /etc/httpd/conf.d/virtual.conf //记住conf.d里面的内容也是apache的配置文件
添加如下内容:
NameVirtualHost 192.168.76.133:80

<VirtualHost 192.168.76.133:80>
ServerName service.example.com
DocumentRoot /var/www/server
</VirtualHost>

<VirtualHost 192.168.76.133:80>
ServerName client.example.com
DocumentRoot /var/www/client
</VirtualHost>
#service httpd restart
这样基于名称的虚拟主机就配置好了
如果你没有DNS你可以再你的机器上hosts文件里加记录 linux在/etc/hosts这个文件 windows在C:\windows\system32\drivers\etc\hosts文件
加上这两行
192.168.76.133    server.example.com
192.168.76.133    client.example.com
这样你在去测试,就会发现访问不同的域名显示不同的内容了 这样基于名称的虚拟主机就配置好了!

3:基于IP地址的虚拟主机
先添加一个临时网卡
#ifconfig eth0:0 192.168.76.132 //临时使用,重启后就会消失
然后便捷virtual.conf文件
#vi /etc/httpd/conf.d/virtual.conf
把内容修改为
#NameVirtualHost 192.168.76.133:80

<VirtualHost 192.168.76.133:80>
ServerName service.example.com
DocumentRoot /var/www/server
</VirtualHost>

<VirtualHost 192.168.76.132:80>
ServerName client.example.com
DocumentRoot /var/www/client
</VirtualHost>
让后你在用ip访问,发现也能显示不同的内容,或者你编辑hosts文件,用域名访问也没问题
这样基于IP地址的虚拟主机也成功了!

4:别名
在/etc/httpd/conf/httpd.conf里加入
Alias /test “/root/website/”    // 别名 这样你用192.168.76.133/test访问 也会显示192.168.76.133的页面
这个地方需要注意的就是/test 还是/test/ 这个是用区别的 你用/test 那么你访问的时候只能用192.168.76.133/test访问   如果你用/test/ 那么192.168.76.133/test/访问,而/test将不会放你访问
忘了这里你的先把/etc/httpd/conf.d目录里面刚刚设置的虚拟目录注释掉 不然没法访问,是因为做了虚拟目录,而httpd.conf里面的设置就无法访问 当然可以用localhost来访问,其他的访问都不行

5:实现网页的资源下载
首先添加别名
#vi /etc/httpd/conf/httpd.conf
在Alias /test “/root/website/” 后面加入
Alias /down “/var/ftp/pub”
让后对/var/ftp/pub区域设置参数
<Directory “/var/ftp/pub”>
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
在Options 加入 MultiViews   //没有index时自动列出目录文档
然后重启服务,这样http://192.168.76.133/down/里面就可以列出/var/ftp/pub里面的文件了,试着点一个另存为,是否可以下载? 呵呵 成功!

6:.htpasswd的实现
#vi /etc/httpd/conf/httpd.conf
我们针对刚刚做的/var/ftp/pub来做
加入如下信息
Alias /down “/var/ftp/pub/”
<Directory “/var/ftp/pub”>
    Options Indexes MultiViews
    AllowOverride AuthConfig
    Order allow,deny
    Allow from all
</Directory>
<Directory “/var/ftp/pub”>
AuthType Basic
AuthName “this is test”
AuthUserFile /etc/httpd/htpasswd
Require User test
</Directory>
然后重启httpd服务,
让后生成.htpasswd用户密码
htpasswd -c /etc/httpd/htpasswd test
让后去访问192.168.76.133/down会需要密码
这样就成功了

Simple jQuery Modal Window Tutorial

Demonstration Download

Introduction

In this tutorial, I’m going to share how to create a simple modal window with jQuery. I like jQuery, it makes everything so simple and so easy. In case you don’t know what’s modal window. You can click here. That’s an example of a modal window.

In this website, I’m using facebox (inspiration from facebook). Others, such as lightbox, thickbox, multibox, litebox…… it’s too many of them and they all are having different features.

Right, let’s start, this example will show you how to create a modal window that will display the content of a DIV #ID.

My objectives are:

  • Able to search the whole html document for A tag NAME=”modal” attribute, so when users click on it, it will display the content of DIV #ID in the HREF attribute in Modal Window.
  • A mask that will fill the whole screen.
  • Modal windows that is simple and easy to modify.

1. HTML code and A tag attributes

  1. <!– #dialog is the id of a DIV defined in the code below –>
  2. <a href=”#dialog” name=”modal”>Simple Modal Window</a>
  3. <div id=”boxes”>
  4. <!– #customize your modal window here –>
  5. <div id=”dialog” class=”window”>
  6. <b>Testing of Modal Window</b> |
  7. <!– close button is defined as close class –>
  8. <a href=”#” class=”close”>Close it</a>
  9. </div>
  10. <!– Do not remove div#mask, because you’ll need it to fill the whole screen –>
  11. <div id=”mask”></div>
  12. </div>
<!-- #dialog is the id of a DIV defined in the code below -->
<a href="#dialog" name="modal">Simple Modal Window</a>

<div id="boxes">

	<!-- #customize your modal window here -->

	<div id="dialog">
		<b>Testing of Modal Window</b> | 

		<!-- close button is defined as close class -->
		<a href="#">Close it</a>

	</div>

	<!-- Do not remove div#mask, because you'll need it to fill the whole screen -->
 	<div id="mask"></div>
</div>

2. CSS code

  1. <style>
  2. /* Z-index of #mask must lower than #boxes .window */
  3. #mask {
  4. position:absolute;
  5. z-index:9000;
  6. background-color:#000;
  7. display:none;
  8. }
  9. #boxes .window {
  10. position:absolute;
  11. width:440px;
  12. height:200px;
  13. display:none;
  14. z-index:9999;
  15. padding:20px;
  16. }
  17. /* Customize your modal window here, you can add background image too */
  18. #boxes #dialog {
  19. width:375px;
  20. height:203px;
  21. }
  22. </style>
<style>

/* Z-index of #mask must lower than #boxes .window */
#mask {
  position:absolute;
  z-index:9000;
  background-color:#000;
  display:none;
}

#boxes .window {
  position:absolute;
  width:440px;
  height:200px;
  display:none;
  z-index:9999;
  padding:20px;
}

/* Customize your modal window here, you can add background image too */
#boxes #dialog {
  width:375px;
  height:203px;
}
</style>

3. Javascript

  1. <script>
  2. $(document).ready(function() {
  3. //select all the a tag with name equal to modal
  4. $(‘a[name=modal]‘).click(function(e) {
  5. //Cancel the link behavior
  6. e.preventDefault();
  7. //Get the A tag
  8. var id = $(this).attr(‘href’);
  9. //Get the screen height and width
  10. var maskHeight = $(document).height();
  11. var maskWidth = $(window).width();
  12. //Set height and width to mask to fill up the whole screen
  13. $(‘#mask’).css({‘width’:maskWidth,’height’:maskHeight});
  14. //transition effect
  15. $(‘#mask’).fadeIn(1000);
  16. $(‘#mask’).fadeTo(“slow”,0.8);
  17. //Get the window height and width
  18. var winH = $(window).height();
  19. var winW = $(window).width();
  20. //Set the popup window to center
  21. $(id).css(‘top’,  winH/2-$(id).height()/2);
  22. $(id).css(‘left’, winW/2-$(id).width()/2);
  23. //transition effect
  24. $(id).fadeIn(2000);
  25. });
  26. //if close button is clicked
  27. $(‘.window .close’).click(function (e) {
  28. //Cancel the link behavior
  29. e.preventDefault();
  30. $(‘#mask, .window’).hide();
  31. });
  32. //if mask is clicked
  33. $(‘#mask’).click(function () {
  34. $(this).hide();
  35. $(‘.window’).hide();
  36. });
  37. });
  38. </script>
<script>

$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior
		e.preventDefault();
		//Get the A tag
		var id = $(this).attr('href');

		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();

		//Set height and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});

		//transition effect
		$('#mask').fadeIn(1000);
		$('#mask').fadeTo("slow",0.8);	

		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();

		//Set the popup window to center
		$(id).css('top',  winH/2-$(id).height()/2);
		$(id).css('left', winW/2-$(id).width()/2);

		//transition effect
		$(id).fadeIn(2000); 

	});

	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		$('#mask, .window').hide();
	});		

	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
	});			

});

</script>

It’s very straight forward and easy to understand. Remember, you need to include jQuery framework.

Demonstration Download

4. Launch modal window with Javascript

Due to popular demand :) , I have an example for it. The concept is simple. I wrapped the modal window script inside a function, and then you will able to call the modal window using javascript function call.

Yes, you will able to load the modal window on page load as well :)

  1. $(document).ready(function () {
  2. //id is the ID for the DIV you want to display it as modal window
  3. launchWindow(id);
  4. });
$(document).ready(function () {
  //id is the ID for the DIV you want to display it as modal window
  launchWindow(id);
});

Launch Modal Window with Javascript

And, if you want to close the modal window on key press, any keys you want, you can add the following function.

  1. $(document).keyup(function(e) {
  2. if(e.keyCode == 13) {
  3. $(‘#mask’).hide();
  4. $(‘.window’).hide();
  5. }
  6. });
$(document).keyup(function(e) {
  if(e.keyCode == 13) {
    $('#mask').hide();
    $('.window').hide();
  }
});

I think I should make another post about modal window. :)

5. Conclusion

Yes, that’s all you need to make a simple jquery modal window. In this tutorial, it shown you the concept of how to display DIV content inside a modal window. However, you can further develop it to accept a link and display it in an iFrame and image gallery.

For those who’s looking for a fully customizable Modal Window, you can try my method, if you have any other questions, please let me know. Thanks for reading.

Update

22-5-2009: – Added a new section “Activate modal window with Javascript”

16-4-2009: – If you prefer this article in Portuguese, please visit Simple jQuery Modal Window in Portuguese by Maujor

27 Mar 09: – Added e.preventDefault() to link to launch the modal window.
- Changed css position to fixed, so that the modal window also fixed to center. – Changed var winH = $(window).height(); to var winH = $(window).height();

24 Mar 09:
- Added e.preventDefault() to cancel the anchor link effect, we can also able to cancel it by removing the href attribute.
- Changed var winH = $(window).height(); to var winH = $(document).height();

EAV model for magento

EAV模型代 表Entity-Attribute-Value,最早用于医学用途,医生在就诊时需要记录很多病人的参数,如体温,年龄,过敏药等情况,而这些参数并不 是每个病人都需要记录的。

由于商品的多样性,用EAV表来描述商品的各种属性也很合适。老牌电子商务应用oscommerce的表设计(为了简洁,我将商品属性名和属性值的 关系表略去):

如何做好一个垂直搜索引擎

本文先引用几句话:
1.“确解用户之意,切返用户之需。”
2.“门户网站都想着是怎样省钱,而不是怎样花钱来买技术。”
3.“搜索引擎不是人人都能做的领域,进入的门槛比较高。”
4.“只是优秀还不够,最好的方式是将一件事情做到极致。”(google十大真理)
5.“做搜索引擎需要专注” “对于一项排到第四的业务,门户很难做到专注。”
6.“用户无法描述道他要找什么,除非让他看到想找的东西。”
7. “所谓楔形,其实就是个倒三角,倒三角的尖端部分代表搜索技术,中部是基于技术的产品应用平台,最上端是对整个搜索引擎用户人群文化的认识和理解,以及现代公司竞争最关键也最捉摸不定的所谓品牌。” “楔形”蕴涵的另一个意义是:楔子要打到墙里,尖端是否锐利很重要,但楔子的破坏性有多强,究竟能在墙面挤压出多大的空间,其中端、后端的沉稳与厚重才是关键。

搜索引擎的技术和理念都是需要时间和经验的积累的,更是需要长期不断的完善进步的,绝对不要认为可以一蹴而就,要达到一个相对成熟领先的搜索引擎从开始到领先的周期一般需要是四年。着急不得。原因是因为搜索引擎太复杂,而且“用户无法描述他要找什么,除非让他看到想找的东西。” 一切都需要摸索,尝试,问题需要一个一个解决,用户的需要得一点点的挖掘。

搜索引擎是一个产品,给用户提供服务的产品,需要长期的不断的改进升级调整才能持续不断的提用户体验,需要满足用户不断增长并且变化的需求、需要不断适应网络的变化。这是因为网络环境是不断变化的、网民的需求也是不断变化的。千万不要把搜索当成项目来做,做完了撂那让用户去用那你肯定没戏。在搜索引擎领域是讲体验的、新的引擎如果用户体验一旦整体上有领先一年以上的差距并且持续2年,那前期的领先者的优势就荡然无存,因为搜索引擎的用户转移成本相对而言是比较低的而且口碑是最佳的传播方式。如果一个搜索引擎不能持续不断的技术创新理念创新,那对于这个搜索引擎来说就等于死亡。我们一般形容搜索引擎的领先是以时间计算的。比如:中搜离百度整体差距

中文分词和TF-IDF

Top 10 Common Web Developer Questions on PHP

As a web developer begins to delve into more complex development tasks, PHP is often their chosen language of choice. We’ve put together a list of the top 10 questions asked about the PHP programming language to get you started!

What is PHP?

PHP is a recursive acronym for “PHP: Hypertext Preprocessor”. PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. Much more info can be found at PHP.net.

Are there online documentation and tutorials that can help me learn PHP?

The manual is on-line here and is also available in other languages and downloadable versions.

For a beginner’s tutorial on PHP, check out this Zend.com tutorial.

Can I run PHP locally on my PC?

Yes, but note that in addition to PHP you will need a web server running on your PC, too. A very convenient and effective way to do this is to download and install Apachefriends.org’s XAMPP, which is an open-source program which will install PHP, Apache web server, MySQL DBMS, and phpMyAdmin onto your PC.

How do you upload images (or other files) using PHP?

We have put together a great tutorial with useful information and example code on this subject.

How can I create a CMS (Content Management System) with PHP?

This is not a trivial project (unless done very poorly and with little to no consideration for security). Consider using one of the many open-source CMS’s which are available. OpenSourceCMS has lots of info on some of the many choices.

I get an error at line number X when I run my PHP script, but I don’t see any problem on that line.

The line number in a PHP parse error message is the line where PHP “got too confused and gave up,” but it’s not necessarily the line where the root cause of the problem occurred. When you get such a message start looking at that line, then start working your way back through the code for various syntax errors (missing “;”, unbalanced brackets or quotes, etc.) It is worth using an editor with PHP syntax color-coding to help you see some of these errors.

My script isn’t working right, but I can’t figure out why.

Learn to code defensively. Do not assume variables are set the way you think they should be; instead check their values before proceeding using functions like isset() and empty(). Learn to use PHP’s error-handling functions.

How can I ask a PHP question in a forum like WebDeveloper.com or PHPBuilder.com and get it answered?

  1. Search. Click on search at the top of the forum and enter your term; the odds are someone will already have asked your question.
  2. Describe. Tell forum members what it should do, how it is to do it and what’s wrong if you’re getting an error. If you’re unsure how to go about something then tell them what it should do and what you have already tried, this provides members with more info about what will and won’t work.
  3. Use the forum’s built in [php] tags around any and all coded sections (HTML as well as PHP). Your code will then be easier to read allowing forum members to be more accurate in their responses.
  4. Indent. I can’t specify this enough, but often the problem could be a simple matter of a missing brace(“{” or “}”); this is more common than you think.
  5. Ask a question. If you just give us information, no matter how accurate, unless forum members know what you want they cannot help you.
  6. If you have a script from a pre-made source, ask the author, they will properly know more about it than forum members.
  7. Cut down. Try to post only the relevant lines unless forum members ask for more. It ensures we will not be put off (and considering that forum members do this for free that’s not the result you want) and can reply quicker.

How can I use PHP to create login-controlled web pages?

This is usually done by using PHP sessions in conjunction with a database. The database contains login information which is used to verify the user’s login. Upon successful login, a session variable can be set. Controlled pages can then first check to see if this session variable exists and is properly set, and if not then redirect the user to the login page. Here is one article of many on the web on this subject.

How do I send emails with PHP?

Simply put, by using the mail() function. For more info, check out this article by Web Developer forum member Bokeh.

The Issue:

I have another ERROR discovered by PEAR PHP_CodeSniffer, http://pear.php.net/package/PHP_CodeSniffer:
End of line character is invalid; expected “n” but found “rn”

And this ERROR is only occurring at the very first line, at , in my PHP code.

The Sollution:

For new files, you can change the default line delimiter to Unix style, such as in Eclipse, you can,
Window –>

How to checking if PEAR works after installation

Verifying command line tool

Both pear and pecl tools should be available everywhere on command line. For that to work, pear’s binary (bin) directory should be in your PATH variable.

To verify it works, simply type pear. A list of commands should be shown:

$

The issue:

I want to install PEAR manager for PHP 5.3.2 with apache on Windows, while run go_pear.bat

Powered by WordPress | Theme: Motion by 85ideas.