Dec 29, 2008

Chewing on Cookies

On vacation this week, but have been doing a little work here and there. Currently I'm figuring out how to work with cookies using Dojo and PHP. So here are a few quick examples if you are ever interested.

Set a Cookie in PHP

<?php
setcookie('CookieName', 'cookie value', time() + 3600 * 24);
?>

Just call the setcookie() function. Set the cookie name and and a value as shown. Notice how the time is set. Get the current time, then add the number of seconds you want the cookie to last. In this example, the cookie would be set to last 24 hours.

Get a Cookie with PHP

<?php
$cookieVar = $_COOKIE["CookieName"];
?>

To get a cookie, just access the global $_COOKIE variable.

Delete a Cookie with PHP

<?php
setcookie ("CookieName", "", time() - 3600);
?>

To delete a a cookie, set the cookie with an empty value and a time value in the pass. This should cause the browser to delete the cookie.

Get a Cookie with Dojo

// Initialize on Load
dojo.addOnLoad(function(){

  var cookieVar = dojo.cookie("CookieName");

});

Call the dojo.cookie() function with the cookie name to get the value of the cookie.

Delete a Cookie with Dojo

function logOff(){
  dojo.cookie("CookieName", "", {expires: -1});
}

To delete a cookie the approach is similar to PHP, set the cookie to an empty value and time, a day in the past.

Dec 18, 2008

Summary of JavaScript Games

I have posted a few links to JavaScript games. I ran across this list of 25 amazing JavaScript games. Very cool stuff. And this is before the next next generation of optimized JavaScript engines. Probably a lot more to come.

Dec 10, 2008

App Server Log Reports [object HTMLInputElement] Instead of Text

Ran into this last week, chalk up another bone headed mistake for Mike. :) Once again, I'm hoping this note will help someone else if they run across this problem.

Problem: I'm using dojo.xhrPost to submit a form to an application server. However, when the data shows up on the application server, instead of text, I am getting [object HTMLInputElement]. Perplexing. If I submit the form without Dojo I seem to get text. What's the deal?

Solution: I was updating someone else's code to use a form for submission. The long and the short of it was, the old code uses "content:" to submit the data. The content attribute is used for creating an object literal list of values to submit data. For example:

myVar = {
  param1:"some value",
  param2:"another value"
}

Fine and dandy when you are using something other than a form.

...
content:myVar,
...

So I had changed the code to this, not noticing the slight change in syntax.

...
content:myForm,
...

However, since a form does not submit its data in this way, mayhem ensues. lol. To fix the problem, replace the above with:

form:myForm,

This results in happiness and joy for all.

Rounded Corners with CSS

Creating rounded corners with CSS is typically achieved with images. While working on my current project, I ran across this tip. CSS3 offers a border-radius property which is unfortunately not implemented in many browsers yet. Firefox does provide an extension for this as described in the article. Consider it a glimpse of the future. :)

Dec 4, 2008

Open Source iTunes Player?

Check out this story on ars technica on Songbird. Its an open source MP3 player with some extras. It doesn't rip CDs yet, but that's coming. Worth checking out.