Writing a Simple Blog Like System in PHP with XML Feed

For a few small projects I needed to develop a simple, easy to manage, blog-like posting system with XML feed support. This can be accomplished relatively easily in PHP using a mySQL Database.

  • First Create a Database called "blog" using PHPMyAdmin or the command line.
  • Add a table called "blogData" to that database.
  • Make sure you have a username and password associated with that Database
  • Create the following fields in the database:

    Field Type
    id int(11)
    title varchar(150)
    by varchar(100)
    date varchar(100)
    content longtext
  • I have included the rest of the files in a zip file - Download it by Clicking Here
  • You will also need to download the TinyMCE editor

The zip file contains the following files:

addArticle.php - editArticle.php - deleteArticle.php - viewPost.php

blog.php - is the main file you can include in any page to view your blog.

feed.php - can be linked from any XML/RSS/Atom Reader - it will provide a valid feed for your blog.

You will need to edit feed.php accordingly.

By admin - 8 April 2008 Comments

New Slider Effect on Portfolio Page

I've been looking to implement a slider effect similar to the one Apple uses on their website for some time now. I recently came across a site describing how to accomplish this feat using the jQuery libarary.

http://css.dzone.com/news/apple-product-gallery-jquery-s

You can check it out in action on my portfolio page:

http://www.tegdesign.com/portfolio.html

By admin - 2 April 2008 Comments

Handling SMS Messages with PHP through E-mail Piping

I have been throwing around a few ideas lately to automate certain tasks via my cell phone. Let's say that I'm in need of some information stored in a database on my webserver, or maybe I just want to upload a photo to my website from my cell phone... what kind of tools do I have to make this happen?

After a few days of thinking about the process I have came up with a nifty little method involving a PHP shell script which used to Pipe an E-mail Message to. Most modern day cell phone's can send email messages. Even my old Nokia allows me to send a text message to a email address.

Here is the PHP script:

#!/usr/bin/php -q
<?php
// read from stdin
 
$fd = fopen("php://stdin", "r");
 
$email = "";
 
while (!feof($fd)) {
 
$email .= fread($fd, 1024);
 
}
 
fclose($fd);
 
// handle email
 
$lines = explode("\n", $email);
 
// empty vars
 
$from = "";
 
$subject = "";
 
$headers = "";
 
$message = "";
 
$splittingheaders = true;
 
for ($i=0; $i < count($lines); $i++) {
 
if ($splittingheaders) {
 
// this is a header
 
$headers .= $lines[$i]."\n";
 
// look out for special headers
 
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
 
$subject = $matches[1];
 
}
 
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
 
$from = $matches[1];
 
}
 
} else {
 
// not a header, but message
 
$message .= $lines[$i]."\n";
 
}
 
if (trim($lines[$i])=="") {
 
// empty line, header section has ended
 
$splittingheaders = false;
 
}
 
}
 
$from = addslashes($from);
 
$subject = addslashes($subject);
 
$message = addslashes($message);
 
$carrierEmail = $from;
 
$triggerName = trim($message);
 
return 0;
 
?>

So as you can see that PHP file is grabbing values from an email message. Specially we are interested in the message body or what I like to call the trigger word (command). This is what will be used to write more PHP code to handle just about any task you could imagine.

So here is how it works:

  • Setup a new email forwarder on your server or at your hosting provider. My host happens to be running Cpanel which makes this really simple.
  • Tell the forwarder to take mail from some account@yourdomain.com and forward it to this
  • |php -q /home/user/mailparser.php

Think it of like having your cell phone send an email to your email address with the words "last10" and it automatically sent you back a list of the last 10 website you went to. You could program a list of commands in a database and have users sign up to manage these commands and build a whole scripting langauge behind automating task whether is be web based or by client installed desktop software. Hell you could program something with this to interface with a desktop application that turned on and off appliances in your house remotely.

Look at large cell phone carriers. They charge over companies money to get sms shortcodes. We've all seen thoose comericals where they say "Text 555 to vote for...". We'll this is essentially a way to bypass paying access charges for obtaining a shortcode on a providers gateway by using an email address and some PHP knowledge to process a request.

I'm interested to here from anyone that would like to collaborate on a project.

By admin - 1 April 2008 Comments

category

archives

others