Posts Tagged ‘server-side’

JavaScript vs Java

Wednesday, July 16th, 2008

Although the names are much alike, JavaScript is primarily a scripting language for use within HTML pages, while Java is a real programming language that does quite different things from JavaScript. In addition Java is much harder to learn. It was developed by Sun for use in pretty much anything that needs some computing power.

JavaScript was developed by Brendan Eich, then working at Netscape, as a client side scripting language (even though there’s no fundamental reason why it can’t be used in a server side environment).

Originally the language was called Live Script, but when it was about to be released Java had become immensely popular (and slightly hypey). At the last possible moment Netscape changed the name of its scripting language to “JavaScript”. This was done purely for marketing reasons. Worse, Eich was ordered to “make it look like Java”. This has given rise to the idea that JavaScript is a “dumbed-down” version of Java. Unfortunately there’s not the slightest shred of truth in this story.

Java and JavaScript both descend from C and C++, but the languages (or rather, their ancestors) have gone in quite different directions. You can see them as distantly related cousins. Both are object oriented (though this is less important in JavaScript than in many other languages) and they share some syntax, but the differences are more important than the similarities.

If you are a C++ or Java programmer you will be surprised by some of JavaScript’s features. Since I don’t have any previous programming experience, the differences are not described on this site. The best you can do is buy David Flanagan, “JavaScript, the Definitive Guide”, 5th edition, O’Reilly, 2006. In this book the differences between C++/Java and JavaScript are clearly explained. I co–edited a few chapters of this book.

PHP:Passing a variable from Javascript to PHP

Saturday, June 28th, 2008

Since Javascript is a client-side technology, and PHP is a server-side technology, the two languages cannot directly share variables. It is, however, possible to pass variables between the two. One way of accomplishing this is to generate Javascript code with PHP, and have the browser refresh itself, passing specific variables back to the PHP script. The example below shows precisely how to do this — it allows PHP code to capture screen height and width, something that is normally only possible on the client side.
<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
// output the geometry variables
echo “Screen width is: “. $_GET['width'] .”<br />\n”;
echo “Screen height is: “. $_GET['height'] .”<br />\n”;
} else {
// pass the geometry variables
// (preserve the original query string
// — post variables will need to handled differently)

echo “<script language=’javascript’>\n”;
echo “ location.href=\”${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}”
. “&width=\” + screen.width + \”&height=\” + screen.height;\n”;
echo “</script>\n”;
exit();
}
?>

Use your primary key phrase in your blog header tags and the title of your posts

Thursday, June 19th, 2008

If your primary key phrase is “business blogging” make sure that the word business, or blogging, or both, appear in your blog headers (the H1 or H2 tags) as well as the title of each of your posts.

Most blogging software will take the keywords in your post title and put them into the file name of the permalink posts it creates.

For example, if you have a blog on Blogger and title your post “Search Engine Optimization For Blogs”, Blogger will automatically create a page with your post and name the file “search-engine-optimization-for-blogs.html” or something similar.

With other server-side software like Wordpress and Movable Type, you may require the mod_rewrite command to save the title of your entries as a permalink.