PHP
First off, we need to read the URL. There are many ways to do this, and here's a useful post that will get you started. For now, we'll assume you can use the file_get_contents function.Reading the URL:
<?php
$content = file_get_contents('http://www.moodsites.com/getMood/12345');
if ($content !== false) {
// Separate the elements of the string to get mood and mood level
$mood = explode('|',$content);
// For clarity, let's assign each element of the array to its own variable
$current_mood = $mood[0];
$current_mood_level = $mood[1];
}
// Unlikely, but in case something went wrong
else {
echo "We couldn't read the mood. Please give it another go.";
}
?>
A little bit about mood data:
Your mood URL will output the mood, the pipe separator, and the mood level. The mood will be either 'happy', 'love', 'randy', 'sad', 'angry', or 'bewildered' - all lowercase. The mood level will be a number between 1 and 100.
Do something with the mood data:
Assuming we're using the same variables as before, let's use the mood variable to display an image of the current mood.
<?php
echo '<img src="images/' . $current_mood . '.jpg" alt="' . $current_mood . '" />';
?>
If your site was happy, this is what you'd get with the above code:
JavaScript
We have a special URL that will output a small script declaring two variables: "usrMood" and "usrMoodLevel". The first is a string, like 'happy', and the second is an integer, between 1 and 100.Simply include the script above your custom JS and you're all set.
Do something with the mood data:
Let's display an image that changes with the mood again, this time with JavaScript. Underneath the script we just created, you can do something like this:
function displayMoodImage(){
document.write('<img src="images/' + usrMood + '.jpg" alt="' + usrMood + '" />');
document.write('<p>' + usrMoodLevel + '</p');
}
</script>
This script, when called with displayMoodImage(), will output an image element pointing to images/mood.jpg, where mood is the current mood, e.g. 'happy', 'sad', etc. Below that it will write the mood level to the screen.


