
May 18th, 2007 by

Jon Moffet
file_get_contents() is a function use to read an entire file to a string. It is occasionally use as a convenient function to retrieve web pages from remote servers in trivial PHP scripts.
However, some web servers has disabled the URL retrieving capabilities in file_get_contents() function for security reasons, this caused scripts written with this function throws out an error which can render the whole web application useless in that particular web server.
To remedy this, you can replace file_get_contents() function with PHP cURL calls. Here's how you can do this.
Before
file_get_contents
After
CURL solution
Although the cURL version seems to be a little bit longer, it is guaranteed to work across servers which place restriction on file_get_contents() and file() function. The use of libcurlemu ensures that the script can work even on a server which doesn't have the PHP CURL extension, which makes this a universal solution for retrieving remote web content from PHP application.
Tags: curl, php, remote, security, php scripts, web hosting, web
Posted in Uncategorized |
3 Comments »

May 16th, 2007 by

Jon Moffet
If you're writing web application that has access to database, then you should be aware that those application are susceptible to SQL Injection attacks which leave information stored in your database vulnerable from a malicious cracker.
This can led attacker to access private areas in your web application, steal sensitive information, erase your database or alter certain information in the database for his own gain. Therefore it is prudent to safeguard your web application by filtering unsafe input variables before inputting them into SQL statements.
How crackers perform SQL Injection
Here is a list of common SQL injection technique employed by malicious users across the internet.
Another good read that I suggest is SQL Injection by examples which provide great explanation of how SQL Injection attacks are performed.
Tags: sql, mysql, injection, security, sqlite
Posted in Uncategorized |
No Comments »

May 16th, 2007 by

Jon Moffet
The practitioner of artificial intelligence and machine learning algorithm will recognize Naive Bayesian as one of the technique use to construct intelligent web application. Naive Bayesian is widely use as an intelligent classifier utilized to automatically classfies data based on statistical probability.
Among the immediate use of Naive Bayesian technique is the classification of (spam) emails, medical diagnosis dan data pattern identification.
Naive Bayesian is able to 'learn' from experience by training it with sample data set to categorized certain type data.
Excellent Naive Bayesian Tutorial
I found an excellent source of PHP Naive Bayesian classifier tutorial written specifically for those who has no background experience in the field of AI and Data Mining :
- Implement Bayesian inference using PHP, Part 1
- Implement Bayesian inference using PHP, Part 2
- Implement Bayesian inference using PHP, Part 3
Other PHP Naive Bayesian Library
Here is a few great naive bayesian implementation written in PHP
- PHP Naive Bayesian Filter
- b8 (formerly bayes-php)
Tags: naive bayesian, bayes, bayesian, php, artificial intelligence, ai, scripts
Posted in Uncategorized |
1 Comment »

May 15th, 2007 by

Jon Moffet
I've decided to share my PHP Detector library to the public which I've coded somewhere around 2006. The library does wonders in detecting IP address geo-location, operating system and the type of browser used based on its user-agent information.
The ip address->geo-location information is provided for free from ShowIP fakap webservice.
The library is handy for for creating web application which serve content depending on users location and type of operating system/browser that he use or for creating web application that collect web surfers statistical data.
Here's how to use Detector library :
PHP:
-
require('detector.php');
-
$dip = &new Detector($_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"]);
-
-
-
echo "$dip->state, $dip->ccode,$dip->town, ($dip->ipaddress) ";
-
echo "using : $dip->browser $dip->browser_version on $dip->os $dip->os_version";
The live demo of Detector library in action can be viewed here : Detector Library demo.
Requirements
- Requires PHP 4.4.0 or 5.0.x
- Requires php cURL extension installed, please refer here for workaround if your server doesn't have PHP cURL extension installed
License
Detector library is licensed under Creative Commons Attribution-ShareAlike 3.0, and can be modified and used in commercial application as long as you share the modified source code with the public.
Tags: php, php library, library, user-agent, browsers, detector, snippets
Posted in Uncategorized |
10 Comments »

May 15th, 2007 by

Jon Moffet
Here's how to send an email with attachment using PHP scripts (via PHPMailer class).
CODE:
-
require("phpmailer/class.phpmailer.php");
-
//****
-
//PLEASE CHANGE THE SETTINGS HERE !!!!
-
//change settings here
-
$your_email = "info@example.com";
-
$your_smtp = "mail.example.com";
-
$your_smtp_user = "info@example.com";
-
$your_smtp_pass = "example_password";
-
$your_website = "http://example.com";
-
//****
-
//get contact form details
-
$name = $_POST['name'];
-
$email = $_POST['email'];
-
$url = $_POST['url'];
-
$comments = $_POST['comments'];
-
$response="Name: $name\nContents:\n$comments\n";
-
$mail = new PHPmailer();
-
$mail = $mail->SetLanguage("en", "phpmailer/language");
-
$mail->From = $your_email;
-
$mail->FromName = $your_website;
-
$mail->Host = $your_smtp;
-
$mail->Mailer = "smtp";
-
$mail->Password = $your_smtp_pass;
-
$mail->Username = $your_smtp_user;
-
$mail->Subject = "$your_website feedback";
-
$mail->SMTPAuth = "true";
-
$mail->Body = $response;
-
$mail->AddAddress($your_email,"$your_website admin");
-
$mail->AddReplyTo($email,$name);
-
-
$mail->AddAttachment("picture.png","picture");
-
-
echo "<p>Thanks for your feedback, <em>$name</em>! We will contact you soon!</p>";
-
if (!$mail->Send()) {
-
echo "<p>There was an error in sending mail, please try again at a later time</p>";
-
}
-
$mail->ClearAddresses();
-
$mail->ClearAttachments();
the key function of this script is $mail->AddAttachment("picture.png","picture.png");, where you can add any file as email attachments from your script.
Hopefully this example will help you to create a useful and flexible mail sending php scripts
Tags: php, email, emails, mail, e-mails, programming, php scripts, scripts
Posted in Uncategorized |
4 Comments »