May 13

Login as root

### Create a folder `installer` ###
mkdir /installer
cd /installer

### Download the installer from apachefriends usin wget ###
wget http://www.apachefriends.org/download.php?xampp-linux-1.6.8a.tar.gz

### Unpack the tar ball to folder `/opt` and install service ###
tar xvfz xampp-linux-1.6.8a.tar.gz -C /opt

lvl=`egrep :initdefault: /etc/inittab|cut -d: -f2`

cd /etc/rc.d/rc${lvl}.d

ln -s /opt/lampp/lampp S99lampp

ln -s /opt/lampp/lampp K01lampp

### Start Server ###
cd /opt/lampp
./lampp start
./lampp status

Tagged with:
Mar 24

Most of the developers nowadays prefer to rewrite URLs for (Search Engine Optimization)SEO. This code is sample on how to strip symbols from a string.

<?php
function urify($str){
  return str_replace(" ","-",trim(ereg_replace("[^A-Za-z0-9[:space:]]", "", $str)));
}
$string = "I really hate symbol on my URL - 12345 What the !£$%^& ~!@#$%^&*()_+=-[]{}";
echo urify($string);
?>

Output is:
I-really-hate-symbol-on-my-URL–12345-What-the

Tagged with:
Mar 19

Google Currency Conversion API

Well, the api is pretty straight forward.
I found it from the Curreny Conversion gadget of iGoogle.

Here is the example:

http://www.google.com/ig/calculator?hl=en&q=1USD%3D%3FPHP

Here is templage in php:

$amount = "1";
$from_Currency = "USD";
$to_Currency = "PHP";

$query_URL = "http://www.google.com/ig/calculator?hl=en&q=$amount$to_Currency.%3D%3F$to_Currency";

The resposnse looks like this:
{lhs: “1 U.S. dollar”,rhs: “45.6704421 Philippine pesos”,error: “”,icc: true}

Not sure if Google is credible to use for conversation, however, if we are just working on simple project, this will be a good help. :-D

Jan 22

I use Hostgator as my hosting company. I love them – great service, tons of space and no long term obligations. And the servers are fast. Now, another reason to love them – running Subversion repositories on your server with the caveat – you can only have one account to account to access that repository. If you develop by yourself, and I do for now, it’s not a problem. So how do you do it – assuming you are a Java coder using Eclipse on Windows?

1. Send Hostgator support a request to get SSH access to your server. They will ask you to send in a picture id and once that is cleared, you should be good to go. A matter of a day or two.

2. Install Subclipse SVN plugin for Eclipse. The Subversive plugin DOES NOT WORK.

3. Install the really good Tortoise SVN client

4. Set up an environment variable called SVN_SSH. To do that, go to the Windows Control Panel -> System -> Advanced -> Environment Variable -> New (under the bottom Window). For variable name enter the value SVN_SSH and for its value enter c:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe (assuming you installed Tortoise SVN in the default location).

5. Start Eclipse and go to the Subclipse options: Window -> Preferences -> Team -> SVN . There, for the SVN Interface select “SVNKit (Pure Java)”. Click OK to store the setting.

6. Now, using Putty or some other SSH tool, SSH to your account. You will need to set up a repository for your project. To do that, create the directory that will be used as repository, say /myrepo. Now, create an Subversion repository inside that directory: svnadmin create myrepo.

7. Create a new project by checking out the repository from SVN. To do that, in Eclipse, go to: File -> New -> Other -> SVN -> Checkout Project From SVN.

8. The ‘Checkout from SVN’ window will appear. There select to create a new repository location

9. For the URL, enter: svn+ssh://@:2222/home//. In other words, if your domain is example.com, your admin user name is joey and the path to your repository is /myrepo, then your URL will be svn+ssh://joey@example.com:2222/home/joey/myrepo

10. Another popup window will follow that will ask you for your SSH user name. Enter the details and make sure they are saved.

11. You should be good to go at that point as the rest of the process is the normal project checkout scheme used by Subclipse.

Tagged with:
Oct 15

Lot of pagination class are available online, and we also created our own. With this class, you can set the number links that will be shown, number of entries per page, and you can also show the last and first page using a cool style.


## Populate data
foreach (range(1, 100) as $value) {
  $rs[] = array("property_id" => rand(100, 1000),
			    "title" => "Hello ".$value
			  );
}

$pagination = new paginationArray();
$pagination->getURL="myPage";
$pagination->numLinks=5;
$pagination->showFirstAndLast=true;
?>
<div stye="float:left;width:500px;">&nbsp;</div><div>
	<?php
	if (count($rs) > 0) {
	  $recordPages = $pagination->generate($rs, 5);
	  if (count($recordPages) != 0) {
	  	echo "<div style='margin-left:350px;'>";
	    foreach ($recordPages as $recordArray) {
	      echo '<p><b>'.$recordArray['property_id'].'</b> &nbsp; : '.$recordArray['title'].'</p>';
	    }
	    echo "</div>";
	    echo "<div><div style='float:left;width:350px;'>&nbsp;</div>".$pagination->links()."</div>";
	  }
	}
	?>
</div>

Download CSS: paginate CSS

Download Class:PaginationClassArray

sample paginate

sample paginate

test paginate class

test paginate class

Tagged with:
Sep 16

We’ve discussed sending both HTML and text mail from our previous post. But there are useful libraries out there to make all our coding easier like PHPmailer and Swiftmailer.

This is an example on how to send multi-part message in swiftmailer.

<?php
// include Swiftmailer Library
require_once("phplib/swiftmailer/lib/Swift.php");
require_once("phplib/swiftmailer/lib/Swift/Connection/SMTP.php");
require_once("phplib/swiftmailer/lib/Swift/Plugin/Decorator.php");  // optional, its a plugin

//define your mail server values
define("MAIL_HOST", "mail.bauson.com");
define("MAIL_USERNAME", "mailer+bauson.com");
define("MAIL_PASSWORD", "bauson.pass");

//instantiate the connection
$smtp = new Swift_Connection_SMTP(MAIL_HOST);
$smtp->setUsername(MAIL_USERNAME);
$smtp->setpassword(MAIL_PASSWORD);
$swift = new Swift($smtp);
$recipients =& new Swift_RecipientList();

// set recipients
$recipients->addTo("jbauson@gmail.com", "my gmail"); //We can give a name along with the address
$recipients->addTo("jbauson@yahoo.com"); //or we can just add the address
$recipients->addTo("jayar@bauson.com", "my private");

//formatting mail
$message =& new Swift_Message("My subject");
$message->setReplyTo(new Swift_Address("dummy@bauson.com", "Fake reply to"));
$message->attach(new Swift_Message_Part("My plain part")); // Plain text version
$message->attach(new Swift_Message_Part("<b>My HTML part</b><hr><tt>hello html</tt>", "text/html")); // HTML version

//The number of successful recipients is returned here (hopefully 3!)
$number_sent = $swift->batchsend($message, $recipients, new Swift_Address("mailer@bauson.com", "BUlk Mailer"));
?>
Tagged with:
Sep 14

Although I expect this article to cause a few ruffled feathers amongst the programming community (since most of them are against HTML email), there are times when the client will ask for it anyway, so you have to know how to do it. We had run into difficulty finding a straight answer on this topic, and many of the articles we had found on it gave us bizarre results in the HTML mail… so once we figured out what worked, we decided to post it.

We have tested this on several different email clients (including but not limited to: Hotmail, Yahoo, AOL, Outlook Express, Outlook, and various text-only email clients such as Mutt).

In the email clients that render HTML (ie – not text-only) the only real difference we found was that Outlook (regular Outlook, not Express) showed the background color from the BODY tags, but not the background image. Yahoo and Hotmail stripped out the background color and images, but if your HTML mail is designed with this in mind, you can easily design around that.

Make sure the email will still look nice if the background color and/or images are stripped out of it.

Obviously, you would change the email addresses and messages to fit your own needs.

 <?php
/* ---------------------------------------------- */
/* ------------ BEGIN PHP SNIPPET ----------------*/
/* ---------------------------------------------- */

$headers .= "FROM: jayar@bauson.com\n";
$headers .= "Reply-To: jayar@bauson.com\n";

// This is the important part!
// This content type identifies the content of the message.
// The boundary delimits the plain text and html sections.
// The value of the boundary can be anything – you can even
// use the same one we used here
$headers .= "Content-Type: multipart/alternative; boundary=\"—-=_NextPart_000_002C_01BFABBF.4A7D6BA0\"\n\n";

// Now begin your message, starting with the delimiter we specified in the boundary
// Notice that two extra dashes (–) are added to the delimiters when
// They are actually being used.
$message = '——=_NextPart_000_002C_01BFABBF.4A7D6BA0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Your plaintext email content here.';

// Now begin your HTML message, starting with the delimiter
// Also notice that we add another content-type line which
// lets the mail client know to render it in HTML
$message .= '——=_NextPart_000_002C_01BFABBF.4A7D6BA0
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

Your HTML email here

——=_NextPart_000_002C_01BFABBF.4A7D6BA0–';

// Now send the mail.
// The additional header, "-f jayar@bauson.com" is
// only required by certain server configurations.
mail($v, "My Multipart Subject", $message ,$headers,"-f jayar@bauson.com");
?>
Sep 11

A friend ask me to send some of my previous work regarding email parser, I don’t have time to go home and search it to my backup drive. This friend is really desperate to finish his task and so by browsing web, I found this really good mailbox class.

Download: receivemail.class

Usage:

<?

include("receivemail.class.php");

$obj= new receiveMail('jayar+bauson.com','mypassword', 'jayar@bauson.com','mail.bauson.com','pop3','110',false);

$obj->connect();         

$tot=$obj->getTotalMails(); 

echo "Total Mails:: $tot<br>";

for($i=$tot;$i>0;$i--)
{
	$head=$obj->getHeaders($i);
	echo "Subjects :: ".$head['subject']."<br>";
	echo "TO :: ".$head['to']."<br>";
	echo "To Other :: ".$head['toOth']."<br>";
	echo "ToName Other :: ".$head['toNameOth']."<br>";
	echo "From :: ".$head['from']."<br>";
	echo "FromName :: ".$head['fromName']."<br>";
	echo "<br><br>";
	echo "<br>***************************************** **************************************************<BR>";
	echo $obj->getBody($i);  

	$str=$obj->GetAttach($i,"./");
	$ar=explode(",",$str);
	foreach($ar as $key=>$value)
		echo ($value=="")?"":"Atteched File :: ".$value."<br>";
	echo "<br>--------------------------------------------------- ---------------------------------------<BR>";

	//$obj->deleteMails($i); // Delete Mail from Mail box
}
$obj->close_mailbox();  

?>
Tagged with:
Sep 09

With a basic knowledge of cURL, you will probably start thinking to design your own class. Check this class to have an idea of what should we have for a basic cURL object, like requesting-browser-like, posting values and crawling pages.

class mycurl {
     protected $_useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1';
     protected $_url;
     protected $_followlocation;
     protected $_timeout;
     protected $_maxRedirects;
     protected $_cookieFileLocation = './cookie.txt';
     protected $_post;
     protected $_postFields;
     protected $_referer ="http://www.google.com";

     protected $_session;
     protected $_webpage;
     protected $_includeHeader;
     protected $_noBody;
     protected $_status;
     protected $_binaryTransfer;
     public    $authentication = 0;
     public    $auth_name      = '';
     public    $auth_pass      = '';

     public function useAuth($use){
       $this->authentication = 0;
       if($use == true) $this->authentication = 1;
     }

     public function setName($name){
       $this->auth_name = $name;
     }
     public function setPass($pass){
       $this->auth_pass = $pass;
     }

     public function __construct($url,$followlocation = true,$timeOut = 30,$maxRedirecs = 4,$binaryTransfer = false,$includeHeader = false,$noBody = false)
     {
         $this->_url = $url;
         $this->_followlocation = $followlocation;
         $this->_timeout = $timeOut;
         $this->_maxRedirects = $maxRedirecs;
         $this->_noBody = $noBody;
         $this->_includeHeader = $includeHeader;
         $this->_binaryTransfer = $binaryTransfer;

         $this->_cookieFileLocation = dirname(__FILE__).'/cookie.txt';

         $this->createCurl($this->_url);
     }

     public function setReferer($referer){
       $this->_referer = $referer;
     }

     public function setCookiFileLocation($path)
     {
         $this->_cookieFileLocation = $path;
     }

     public function setPost ($postFields)
     {
        $this->_post = true;
        $this->_postFields = $postFields;
     }

     public function setUserAgent($userAgent)
     {
         $this->_useragent = $userAgent;
     }

     public function createCurl($url = 'nul')
     {
        if($url != 'nul'){
          $this->_url = $url;
        }

         $s = curl_init();

         curl_setopt($s,CURLOPT_URL,$this->_url);
         curl_setopt($s,CURLOPT_HTTPHEADER,array('Expect:'));
         curl_setopt($s,CURLOPT_TIMEOUT,$this->_timeout);
         curl_setopt($s,CURLOPT_MAXREDIRS,$this->_maxRedirects);
         curl_setopt($s,CURLOPT_RETURNTRANSFER,true);
         //curl_setopt($s,CURLOPT_FOLLOWLOCATION,$this->_followlocation);
         curl_setopt($s,CURLOPT_COOKIEJAR,$this->_cookieFileLocation);
         curl_setopt($s,CURLOPT_COOKIEFILE,$this->_cookieFileLocation);

         if($this->authentication == 1){
           curl_setopt($s, CURLOPT_USERPWD, $this->auth_name.':'.$this->auth_pass);
         }
         if($this->_post)
         {
             curl_setopt($s,CURLOPT_POST,true);
             curl_setopt($s,CURLOPT_POSTFIELDS,$this->_postFields);

         }

         if($this->_includeHeader)
         {
               curl_setopt($s,CURLOPT_HEADER,true);
         }

         if($this->_noBody)
         {
             curl_setopt($s,CURLOPT_NOBODY,true);
         }
         /*
         if($this->_binary)
         {
             curl_setopt($s,CURLOPT_BINARYTRANSFER,true);
         }
         */
         curl_setopt($s,CURLOPT_USERAGENT,$this->_useragent);
         curl_setopt($s,CURLOPT_REFERER,$this->_referer);

         $this->_webpage = curl_exec($s);
                   $this->_status = curl_getinfo($s,CURLINFO_HTTP_CODE);
         curl_close($s);

     }

   public function getHttpStatus()
   {
       return $this->_status;
   }

   public function __tostring(){
      return $this->_webpage;
   }
}
Tagged with:
Sep 08

I just found out that my free link checking tool is being blocked by some websites. My guess is that it’s because it’s sending a blocked User-Agent string. I’m going to tweak it to say it’s FireFox or something. Here’s how to do that with cURL and PHP:

// spoofing FireFox 2.0
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

$ch = curl_init();

// set user agent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
// set the rest of your cURL options here
Tagged with:
preload preload preload
Bless CV