Simple AJAX Example
This aims to be the easiest possible example demonstrating AJAX (Asynchronous JavaScript and XML).
AJAX is a technique rather than a technology: It describes how JavaScript can be used to pull data from the server using the XML HTTP Request object and then insert this data into the website using DOM. This is done asynchronously – that is, in the background, without having to refresh the whole page. The technology which AJAX is based on has already been available for a while, the combination is what makes it new.
You can try the examples online or download them and run them locally (except for the PHP script, that would require a webserver with PHP).
1. The DOM
The Document Object Model is the internal representation of your website. The DOM is accessible by JavaScript and provides a way to programmatically insert, remove and modify tags in your website (except that they are called elements or nodes instead of tags, because the DOM manipulates the data model in memory and not the representation as XML). This example shows how to set the content of the element with the id “foo” to “Hello, AJAX world!”: Read more…
Stop PHP nobody Spammers
PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.
Watching your exim_mainlog doesn’t exactly help, you see th email going out but you can’t track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.
If you check out your PHP.ini file you’ll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP – so everything will go through /usr/sbin/sendmail =)
Requirements:
We assume you’re using Apache 1.3x, PHP and Exim. This may work on other systems but we’re only tested it on a Cpanel/WHM Red Hat Enterprise system. Read more…
Rotating Banner in PHP
This is a snippet that will rotate a banner on a page. All you have to do is set $File and $Images to the paths to the images. It will just do the next image in $Images in order. It doesn’t rotate banners for seperate users, it just goes through. Before you use it, create the $Stat file and set the contents of it to 0 and your ready to go!
Read more…
Text counter in PHP
A counter is an essential part of a site to know how many people are coming to site. Here is an easy way to make a counter. All you need is access to PHP and be able to chmod a directory. We’re going to save the amount of hits in a .dat file, so you don’t even need a mySQL database. First off, you have create a directory and CHMOD it 777 so PHP can write the counter.dat file.
Here is what we have to do:
- Use the file_exists() function in PHP and see if the counter.dat file exists. If it does, then open the file using the PHP fopen() function.
- Use the PHP fgets() function to find the number of hits there and save it in a variable.
- Add one to the variable.
- Close the file.
- Display the number of hits.
- Open the counter.dat file using the fopen() function and save it as a variable.
- Use the PHP fputs() function to insert the new number of hits.
- Close the file.
- If the counter.dat file doesn’t exist, then use the fopen() function and declare it as a variable.
- Use the Fputs() function and put a “1″ in there.
- Print out that 1 person has come to the page and then close the file.
Here is the code: Read more…
Changing Web Hosts ? Step-By-Step Guide
by Tweak on June 16, 2009
in Domain/Hosting
Every webmaster cringes at the thought of moving hosts. Like moving your home it can be messy and sometimes problems arise. But if you follow these simple steps, your move will be less painful.
Backup Backup Backup
If you’ve been diligent with your backups, you’ve got a lot of insurance to fall back on yet always make the latest backup. If you haven’t, before you do anything else, do a backup now. Backup anything and everything you can and don’t forget your database if your site relies on it. Save at least 2 copies and store them separately. One for you to work with, and the other as an archive. Do not underestimate how easy it is to copy over these files as you make changes or simply mess it up.
If you’re moving to a host who has as different control panel, make a manual backup by downloading all your files because different control panels may not be able to restore the backups made by your old host. They also have different directory structures so your file trees will be in a mess. If you need to, make a small note file with notepad with memos for you to remember the old server configurations. This will help you as you make changes on your new host server and save the confusion moving back and forth between hosts. Remember to make the correct transfer type (ASCII or Binary) as you download. If your download is not right chances are you’ll have a tough time getting your site to work on the new host server.
If server logs are especially important, remember to backup those too. There is no good way of moving logs yet because different hosts may log statistics differently. So the best thing to do is to download it and use a log analyzer on your computer to make references to later on.
Read more…
Create Random Text in PHP
Want to put a random quote on your site? Or randomize some other aspect of your site? It’s easy. You’ll want to use PHP or some other server-side scripting language instead of a client-side scripting language like JavaScript. Server-side languages write the content to the page in html before it ever leaves the server. Search engines will be able to read the content on your page, but with JavaScript they cannot, so you lose any content value of the random code. Also, if a user turns off JavaScript, that random content is lost. Google, MSN, and Yahoo will see that the content is changing often, and that may help your rankings (depending on your implementation).
Here’s how to put the random elements into your page, using PHP.
Step 1:
Create a text file called ‘myData.txt’. Open the file and put in your random elements, placing each random element on its own line, (whether text, images or html). Then place ‘myData.txt’ in the same directory as your page containing the PHP script.
Step 2:
Place the following PHP code into your page where you want the random element:
Read more…
IP country block downloads
All country IP block files are provided in CIDR format, at this time. Please note that we compile these lists from regional IP space providers. To correct any errors please contact your local IP space provider e.g. for Europe it’s Ripe, for North America it’s Arin.
Zone files last updated: Mon Jun 15 05:07:15 EDT 2009
Download compressed tar archive with all zone files in it: all-zones.tar.gz
Read more…
Installing Lighttpd With PHP5 Support On CentOS
Lighttpd is a secure, fast, standards-compliant web server designed for speed-critical environments. This tutorial shows how you can install Lighttpd on a CentOS 5.0 server with PHP5 support (through FastCGI) and MySQL support.
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
Afterwards, we can install Lighttpd like this:
yum install lighttpd Read more…
How to install winrar on CentOS
Rar is one of the common file format use for data compression and archiving. What happen if you have a rar file in Linux ? Don’t panic, just using the ‘rar’ program .There is some intro in Unrar the File.
Today I had to install rar support to archive and split large files. I’ve tried to download an rar from rarlab site
wget http://www.rarlab.com/rar/rarlinux-3.9.b2.tar.gz
Extract it:
tar -xf rarlinux-3.8.0.tar.gz
cd rar
Copy rar & unrar files to /usr/bin:
cp rar unar /usr/bin Read more…
Script to daily email APF status
You are running APF on your server, but sometimes you think “is APF running fine ?”
This script sends you an email with APF satus.
Log in to your server as root
Create the script:
nano apfstatus.sh
Put this on the file:
#!/bin/bash
tail -200 /var/log/apf_log | mail -s "APF Status" youemail@domain.com
Save and Exit
Ctrl+X and Y
Read more…