Using Yahoo! Social SDK for PHP to build a simple message board. Users will be able to login and post messages with their Yahoo credentials.
First register a new application on Yahoo. Record the Application ID, Consumer Key and a Consumer Secret.
Create a database to keep track of the people (guid) and posts:

Download Yahoo! Social SDK for PHP and upload it to your server. We need the ‘lib’ directory. Then create four more files (database.class.php, delete_message.php, index.php, and process_message.php). The file structure looks like this:

Update database.class.php with your database information:
<?php
define('SERVER', 'your_database server');
define('DB_USER', 'your_database_username');
define('DB_PASS', 'your_database_password');
define('DB_NAME', 'your_database_name');
class Database {
private $connection;
function __construct() {
$this->open_connection();
}
public function open_connection() {
$this->connection = mysql_connect(SERVER,DB_USER,DB_PASS);
if (!$this->connection) {
die("Database connection failed: " . mysql_error());
} else {
$db_select = mysql_select_db(DB_NAME,$this->connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
}
}
public function close_connection() {
if (isset($this->connection)) {
mysql_close($this->connection);
unset($this->connection);
}
}
public function query($sql) {
$result = mysql_query($sql, $this->connection);
$this->confirm_query($result);
return $result;
}
private function confirm_query($result) {
if (!$result) {
die("Database query failed: " . mysql_error());
}
}
public function escape_value( $value ) {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( "mysql_real_escape_string" );
if ($new_enough_php) {
if ($magic_quotes_active) {
$value = stripslashes($value);
}
$value = mysql_real_escape_string($value);
} else {
if (!$magic_quotes_active) {
$value = addslashes( $value );
}
}
return $value;
}
public function fetch_array($result_set) {
return mysql_fetch_array($result_set);
}
public function num_rows($result_set) {
return mysql_num_rows($result_set);
}
public function affected_rows() {
return mysql_affected_rows($this->connection);
}
}
$db = new Database();
?>
Update index.php with your Consumer Key, Consumer Secret and Application ID:
<?php
require_once("lib/Yahoo.inc");
define('CONSUMER_KEY', "your_consumer_key");
define('CONSUMER_SECRET', "your_consumer_secret");
define('APPID', "your_app_id");
$session = YahooSession::requireSession(CONSUMER_KEY,CONSUMER_SECRET,APPID);
require_once('database.class.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Message Board</title>
<style>
table {
width:80%;
}
td {
background-color: #eee;
}
th {
background-color: #ddd;
}
#post_form {
padding: 20px;
}
</style>
</head>
<body>
<h1>Simple Message Board</h1>
<?php
// fetch the logged-in (sessioned) user
$user = $session->getSessionedUser();
// fetch the profile for the current user.
$profile = $user->getProfile();
// display form to post a message
echo "<form action=\"process_message.php\" method=\"post\">\n";
echo "<div id=\"post_form\">\n";
echo "<input type=\"hidden\" name=\"guid\" value=\"{$user->session->guid}\" />\n";
echo "<input type=\"hidden\" name=\"name\" value=\"{$profile->nickname}\" />\n";
echo "<input type=\"text\" name=\"message\" value=\"\" />\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Post Message\" />\n";
echo "</div>\n";
echo "</form>\n";
// display messages from the database
echo "<table>\n";
echo "<thead>";
echo "<tr><th>Date</th><th>Nickname</th><th>Content</th><th>Owner</th></tr>";
echo "</thead>\n";
$query = "SELECT * FROM posts ORDER BY date DESC";
$result = $db->query($query);
while ($row = $db->fetch_array($result)) {
echo "<tr>";
echo "<td>{$row['date']}</td>";
echo "<td>{$row['name']}</td>";
echo "<td>{$row['message']}</td>";
// if this message was posted by the logged in user offere a delete link
if ($user->session->guid == $row['guid']) {
echo "<td><a href=\"delete_message.php?id={$row['id']}&guid={$row['guid']}\">delete</a></td>";
} else {
echo "<td></td>";
}
echo "</tr>\n";
}
echo "</table>\n";
?>
</body>
</html>
delete_message.php removes a message from the database:
<?php
require_once('database.class.php');
$guid = $db->escape_value($_GET['guid']);
$id = $db->escape_value($_GET['id']);
$query = "DELETE FROM posts where guid = '$guid' and id = '$id' LIMIT 1";
$db->query($query);
header('Location: index.php');
?>
process_message.php inserts a new message into the database:
<?php
require_once('database.class.php');
$guid = $_POST['guid'];
$name = $_POST['name'];
$message = $db->escape_value($_POST['message']);
$query = "INSERT INTO posts (guid,name,message) VALUES ('$guid','$name','$message')";
$db->query($query);
header('Location: index.php');
?>
View a demo here.