Archive

Archive for the ‘PHP Solutions’ Category

Simple Google SERP Parser in PHP

February 10th, 2010 No comments

If you need an easy way to extract all links from Google SERP page, here is the script:

<?
set_time_limit(0);
// Here is our search term
$search=”Test search”;
// Let’s prepare it for Google
$slovo=urlencode(trim($search));
// Here comes the Google URL
$google=”http://www.google.com/search?q=”.$slovo.”&num=10″;
// Let’s place all the links into a single file.
$links=fopen(“$slovo.txt”,”a+”);
// Getting the page contents from Google
$content= @file_get_contents($google);
// Simple and dirtty regular expression, that does the job :) $matches is the result.
preg_match_all(‘/<h3><a href=”([^">]+)/’, $content, $matches);
// Here are our urls: let’s echo them and write to a file
foreach ($matches[1] as $url)
{
echo $url.”\r\n”;
fwrite($links, $url.”\r\n”);
}
fclose($links);

?>

It works at the moment; Google might change the SERP output format, then you will need to change the regexp. The rest is very simple, this script should work on any host, even without cURL support.

Free PHP/MySQL Help Desk Software Script

February 8th, 2010 No comments

If you need to communicate with your customers to solve their problems, you definitely need a help desk. A place, where all most popular questions are answered and users have the ability to ask if anything remains unclear. If you are running a service, a web hosting, or anything else related to a big number of potential customers, help desk software will make it easier to communicate with them.

There are lots of help desk scripts available on the web. Everything depends on your current needs; if you’re installing it for the first time, you should better choose a free or open source solution. Here is a big list of software to choose from, but I will tell you a little about the script I really like. It’s Hesk.

IMHO, it’s a great script for a beginner and for a pro. Interface is very clear and you don’t even need a documentation, as it’s hard to do anything wrong with this script. Take a look at a screenshot:

Let’s find out what are the features:

Customer Interface:

* Submit new tickets
* Attach files
* Obtain detailed information from customers with custom fields
* SPAM prevention
* Suggest related articles before final ticket submission
* View existing ticket status
* E-mail notifications of staff replies
* Browse knowledge base

Knowledge base:

* Unlimited knowledge base articles
* Unlimited categories and subcategories
* Quick and Easy search capabilities
* Post attachments to articles
* Count article views
* List newest and most popular articles
* Rate articles

Administrator interface:

* Unlimited administrators and staff accounts
* Restricted access to some functionality for certain staff
* Powerful ticket search ability
* Manage knowledge base categories and articles
* Manage staff accounts
* Manage canned responses
* Customize help desk settings
* Modify your profiles and signatures
* Autoclose tickets after X days
* E-mail notifications of new tickets and replies
* Customers can easily rate staff replies
* Easy translation into any language

You are welcome to download your free version.

If you can propose any other simple and free scripts, please, post them in comments.

How to Send an E-mail Using PHP and Gmail

February 6th, 2010 No comments

It is not a secret, that most e-mails that are sent by mail() function are not delivered due to spam filters enabled. Even if you pass all the necessary headers, your message is often delivered to SPAM folder and in fact will never be read. In order to avoid this, we will send e-mails using a free class and Gmail SMTP. You need to have a Gmail account to use this method, but I think it should not be a problem. You will also have to pass your Gmail password to this script.

First of all, we will need a class to send e-mails using SMTP. It can be obtained here. We will also need a Gmail account, that has SMTP enabled. Make sure to check your settings tab to enable SMTP (it is enabled by default, but it is better to check this once again).

Then we will use the following code:

$mail = new PHPMailer();
// Recipient’s e-mail address
$email=”me@lampdocs.com”;
// Message text (may contain HTML)
$milo=”Some text comes here”;
$mail->Mailer = “smtp”;
$mail->Host = “ssl://smtp.gmail.com”;
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = “youraccount@gmail.com”; // SMTP username
$mail->Password = “yourpass“; // SMTP password

$webmaster_email = “youraccount@gmail.com”; //Reply to this email ID
$name=”Preferred Buyer”; // Recipient’s name
$mail->From = “youraccount@gmail.com”;
$mail->FromName = “Youraccount.com”; // Edit this to select “From” header
$mail->AddAddress($email, $name);
$mail->AddReplyTo($webmaster_email, “Youraccount.com”);
$mail->WordWrap = 70; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = “This is my test message”;
$mail->Body = $milo; //HTML Body
$mail->Send();

All you need to start using this free script is to set up your Gmail access information and compose a message. All the necessary headers will be created automatically.

This method allows to send e-mails with html links, as most e-mails sent using other methods are blocked by spamasassin, or similar anti spam software.

How to Send an ICQ Message With PHP Script

February 3rd, 2010 No comments

Today I will show you how to send ICQ messages using . We will need a class, named Webicqlite. You can download it and rename to WebIcqLite.class.php.

Sending ICQ messages never been so easy with this class. In order to test it, we will need login and password for ICQ, if you don’t have it, you can obtain it at ICQ.

Here comes the code listing:

<?php
// Let’s connect our main class
include(‘WebIcqLite.class.php’);
// replace 111111111 with your ICQ UIN
define(‘UIN’, 111111111);
// Put your ICQ password
define(‘PASSWORD’, ‘password’);
// Creating an object
$icq = new WebIcqLite();
// Trying to connect to ICQ server
if($icq->connect(UIN, PASSWORD)){
// Trying to send a message to 123456789 (replace with your desired destination number)
if(!$icq->send_message(’123456789′, ‘Hello from php!!!’)){

echo $icq->error;

}else{

echo ‘Message sent’;

}

$icq->disconnect();

}else{

echo $icq->error;

}

?>

Everything seems to be simple. I am using it to notify myself about server events, like server overload, scheduled backup, etc. It is just a single feature of this class, I will post more solutions a bit later. If you need any specific solution, please, let me know.