The following script will use PHP and Ajax (XMLHTTPRequest) to retrieve current server time in every 10 seconds and then insert the date/time into the html page.
1, html file: time.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Auto-refreshing dynamic content using AJAX and PHP</title>
<script type="text/javascript" src="time.js"></script>
</head>
<body onload="ajax(page,'scriptoutput')">
<p>Current Server date & time (updated every 10 seconds):<br />
<span id="scriptoutput"></span></p>
</body>
</html>
2, Ajax file: time.js
var page ="/time.php?time="+date.getTime();
function ajax(url,target)
{
// native XMLHttpRequest object
document.getElementById(target).innerHTML = 'sending...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send();
}
}
setTimeout("ajax(page,'scriptoutput')", 10000); //10 seconds
}
function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 || req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText;
}
}
}
3, PHP file: time.php
<?php
putenv('TZ=America/New_York');
echo date("Y-m-d h:i:s A", time());
?>
4, Save and upload these files to your server, open time.html and you will see the html page refreshes it’s time every 10 seconds.
Ref: http://www.openhosting.co.uk/articles/webdev/6004/
Tags:
PHP
Permalink
March 22, 2008 at 5:55 pm
·
1, Prevent DOS Attacks
download and install mod_evasive: http://www.zdziarski.com/projects/mod_evasive/
2, Limit MySQL Network Access
edit /etc/my.cnf to add the following line:
skip-networking
bind-address = 127.0.0.1
3, change MySQL root user’s password:
mysql mysql -u root
UPDATE user SET Password=PASSWORD(‘xxx’) WHERE user=’root’;
flush privileges
4, Disable PHP functions:
edit etc/php.ini add the following line
disable_functions = show_source, system, shell_exec, passthru, phpinfo, proc_open, proc_nice
make sure the following parameters are set correctly:
register_globals = Off
allow_url_fopen = Off
allow_url_include = Off
display_errors = Off
log_errors = On
Ref: http://www.conftool.net/en/technical_documentation/security_hints.html
Tags:
Linux
Permalink
March 20, 2008 at 7:12 am
·
Use the following shell script to send you an email (use cron job)
#!/bin/sh
#TODAY=$(date)
#echo $TODAY
Year=`date +”%C%y”`
Month=`date +”%b”`
Day=`date +”%d”`
cat /var/log/httpd/*.log* |grep “login”|grep $Day/$Month/$Year>login.log
mail xxx@gmail.com -s “apache login attempts” <login.log
Tags:
Linux
Permalink
March 19, 2008 at 8:59 am
·
1, Tuning Apache:
1.1 Edit httpd.conf, Configuration of the prefork MPM
StartServers 50
MinSpareServers 15
MaxSpareServers 30
MaxClients 225
MaxRequestsPerChild 4000
1.2, Make sure KeepAlive is on
KeepAlive On
2, Tuning PHP:
2.1 Install eAccelerator
see http://www.my-whiteboard.com/linux-admin/how-to-install-eaccelerator-for-php-on-centos-and-redhat.html for details, commands:
wget http://downloads.sourceforge.net/eaccelerator/eaccelerator-0.9.5.2.zip?modtime=1188830343&big_mirror=0
unzip eaccelerator-0.9.5.2.zip
cd eaccelerator-0.9.5.2.zip
phpize
./configure –enable-mmcache=shared –with-php-config=/usr/bin/php-config
make; make install
cp eaccelerator.ini /etc/php.d/.
2.2. Edit /etc/php.d/eaccelerator.ini,
vi /etc/php.d/eaccelerator.ini
extension="eaccelerator.so"
;zend_extension="/usr/lib/php4/eaccelerator.so"
eaccelerator.shm_size=”64″
eaccelerator.shm_ttl = “60″
2.3. Make sure /etc/sysctl.conf has enough maximum shared memory size.
kernel.shmmax = 4294967295
2.4. Run sysctl -p
sysctl -p
2.5. Edit php.ini (/etc/php.ini)
max_execution_time= 30
max_input_time = 60
memory_limit = 32M
output_buffering = 4096
3. Restart apache:
apachectl restart
Tags:
Linux
Permalink
March 18, 2008 at 10:24 pm
·
1, yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps
2, chkconfig tomcat5 on
3, Turn on Servlet Reloading
To turn on servlet reloading, edit Edit install_dir/conf/context.xml and change
<Context>
to
<Context reloadable="true" privileged="true">
4, Link your java application
mv /var/lib/tomcat5/webapps/ROOT /var/lib/tomcat5/webapps/ROOT_
cd /var/lib/tomcat5/webapps/
ln -s /home/metrohomedb/metrohomedb ROOT
5, start tomcat
service tomcat5 restart
Tags:
Linux
Permalink
March 18, 2008 at 7:26 pm
·