
March 26th, 2007 by

Jon Moffet
Everybody knows, spam is an annoying thing in the internet. Especially when you create a Contact Form or a Guestbook only to have it filled with junk messages.
Luckily the folks at Automattic have created Akismet as a measures to combat web spams, and best of all it can be integrated right inside your own customized PHP scripts.
First of all, you need to download Akismet PHP4 Class library (and it works with PHP5 too!)
Then get the Wordpress API key from Wordpress.com, simply sign up for an account there, and the API key can be obtained from "My Account" link at the top right when you log in.
Then include akismet.php class file in your php file that does form processing.
PHP:
-
require('akismet.class.php');
-
-
$wpkey = '**YOUR WORDPRESS KEY***';
-
-
-
'author' => $comment_author,
-
'email' => $comment_author_email,
-
'website' => $comment_author_website,
-
'body' => $comment,
-
'permalink' => $comment_guestbook_url,
-
'user_ip' => $comment_author_ip,
-
'user_agent' => $comment_author_user_agent,
-
);
-
-
// instantiate an instance of the class
-
$akismet = new Akismet('http://fakapster.com/', $wpkey, $comment);
-
-
-
if($akismet->isSpam()){
-
// store the comment but mark it as spam (in case of a mis-diagnosis)
-
//display a warning
-
-
die('your comment is marked as spam');
-
-
-
-
} else {
-
//this comment is not a spam
-
-
//insert comment into database code
-
-
}
Your guestbook (or online form) should be fairly resistant to spam attacks if you implement anti-spam measures using this method.
Tags: akismet, spam karma, php, anti spam, antispam, spam, spam comments, spams, phpclass
Posted in Uncategorized |
7 Comments »

March 24th, 2007 by

Jon Moffet
Those who run websites on Apache Web server will mostly familiar with the Apache .htaccess file which is used as configuration file on a particular directory. The use of .htaccess file is extremely popular with shared web hosting plans due to its flexibility.
.htaccess file can be use to
- Block access to website from certain ip addresses
- Create password protected directory
- Protects your file from hotlinking
- Block hitbots and spam bots
- Help create customized error page (404 ,401, 501,503 page)
However each of the task listed above requires different htaccess directive in order to make it work. Coupled with Regular Expression, .htaccess file might no be intuitive to average web masters.
Luckily there's http://www.htaccesstools.com/ which helps you generate the rules mention above. The website is relatively simple to use and easy to understand.
It even features .htaccess help forum for those who have questions about writing .htaccess files.
All in all, http://www.htaccesstools.com/ is a worth website bookmarking for, especially if you're running websites powered by Apache web server.
Tags: apache, php, htaccess, webhosting, web hosting
Posted in Uncategorized |
No Comments »

March 18th, 2007 by

Jon Moffet
Libchart is a lightweight PHP class library which can be use to create charts. It support creating Horizontal Bar , Vertical Bar, Pie chart and Line graph which is useful for data representation on your PHP scripts.
Here's a sample of Libchart output :



Sample Code
PHP:
-
include "libchart/libchart.php";
-
-
header("Content-type: image/png");
-
-
$chart = new VerticalChart(500,250);
-
-
$chart->addPoint(new Point("Jan 2005", 273));
-
$chart->addPoint(new Point("Feb 2005", 321));
-
$chart->addPoint(new Point("March 2005", 442));
-
$chart->addPoint(new Point("April 2005", 711));
-
-
$chart->setTitle("Monthly usage for www.example.com");
-
$chart->render();
You can download Libchart from its author's website.
Alternatively you can use JpGraph to produce chart with PHP. However Libchart is much simpler to use and it can be used freely in commercial applications without requiring you to pay extra licensing fees.
Tags: php, jpgraph, library, chart, phpclass
Posted in Uncategorized |
No Comments »

March 16th, 2007 by

Jon Moffet
libcurl or php curl extension is a flexible multiprotocol client library widely in use in various PHP scripts. It can be use to access FTP,HTTP,HTTPS,DICT,TELNET,SCP and LDAP protocol.
libcurl is popular among PHP programmers because it support various HTTP methods which can be use to create web robot, crawler and auto-submitters by emulating a web browser.
However for various reasons, some web hosting company choose not to install php-curl extension and this will affect your php scripts which uses curl_* functions.
Solution :
To solve that problem, you can download and use libcurlemu, a pure PHP implementation of libcurl. By using this library, your php scripts is guaranteed to run regardless if php curl extension is installed or otherwise.
Adapting your scripts to php curl is simple, you only need to include "libcurlemu.inc.php" in your scripts, and everything will run as if the server has php curl installed. There are no further modifications required to use libcurlemu.
Example :
PHP:
-
// first, include libcurlemu.inc.php
-
require_once('libcurlemu.inc.php');
-
-
//... the rest of your scripts is under here, unmodified
-
$ch = curl_init();
-
-
curl_setopt($ch, CURLOPT_URL,"http://www.mysite.com/tester.phtml");
-
curl_setopt($ch, CURLOPT_POST, 1);
-
curl_setopt($ch, CURLOPT_POSTFIELDS,
-
"postvar1=value1&postvar2=value2);
-
curl_exec ($ch);
-
curl_close ($ch);
libcurlemu will attempt to use the native PHP Curl extension before it switches to its own library, this will ensure that your scripts will run portably without any further modification when you ported it to a server with PHP curl extensions installed.
Tags: php, curl, libcurl, library, extensions
Posted in Uncategorized |
2 Comments »

March 14th, 2007 by

Jon Moffet
Here's a quick way to convert php date() into a format acceptable to be stored in MySQL database 'Date Time' field
If you want to store the time in MySQL 'Date' field then you can use this code
you can later insert $date into MySQL "Date" or "Date Time" field to be manipulated by the database later.
Example of MySQL 'Date' value :
- 2007-03-11 18:52:42
- 2007-03-11
Tags: php, date, mysql
Posted in Uncategorized |
No Comments »