A potpourri of Web Developmemt, Linux, and Windows tidbits and observations

Ubuntu 10.04 “Lucid Lynx” is coming!

Posted by dale | Ubuntu | Sunday 28 February 2010 3:03 pm

The next release of Ubuntu, version 10.04, “Lucid Lynx” is set for April 29, 2010. The Alpha 3 version is out, and there is much buzz about what to expect from the next release.

This release is set for long term support which offers bug fixes and security patches for three years for desktops and five years for servers. Usually the six month Ubuntu releases are supported for only 18 months.

Something that all the Linux distros have struggled with is keeping up with video drivers. Ubuntu has made a concerted effort to support NIVDIA drivers, even though NIVIDIA keeps its drivers proprietary. With this release, the Nouveau project will be the standard NVIDIA project used by Ubuntu. The Nouveau project specializes in high quality, open source drivers for NIVDIA cards. This is good news for system builders, who are major users of Ubuntu, and favor NIVDIA graphic cards. Currently, Nouveau offers full 2D support for NVIDIA cards. 3D support is not quite there yet, but there working on it.

Along with this, transparency in all areas of the desktop and in applications will be supported.  GNOME 3 will be available in March, before Lucid Lynx, with additional functionality for the desktop.  What all this means is that those fancy aero screens in Vista and Windows 7 with desktop stunning images now will be possible in the Ubuntu desktop. With Gnome 3 and transparency coming to 10.4, we could be pleasantly surprised with a considerable upgrade in “eye candy” for this release.

New applications include easier file sharing between Windows and Ubuntu implemented with Personal File Sharing.   Gwibber will allow for easier social networking by retrieving and combining information from Facebook, Twitter, Flickr, and Digg to name a few social sites.  And there will be  support for Apples  iPhones and iTouch drag and drop in Rythmbox.

Much effort has been put into getting Ubuntu to boot quickly. Ten second boots has been the goal. This new release will be close to that goal. Boots from 10-15 seconds have been reported. That’s incredible! We’re getting closer and closer to “Instant On.”   Microsoft, which touted quick booting as a feature of Windows 7, takes twice as long. A splash screen has been added to start,  so you don’t have a period of time with nothing on your monitor while booting during that 10 seconds that is.  I’m still blown away by this kind of boot time, just amazing.

Ubuntu is getting very close to being a better operating system environment for computer hardware and software than Microsoft Windows. If the public becomes knowledgeable about just how good Ubuntu is, we could see a positive shift in Ubuntu’s market share.

Passing Variables – The PHP $_SESSION array

Posted by dale | PHP | Saturday 27 February 2010 7:40 pm

The problem of storing user information while the user is accessing the web site is solved with sessions in PHP. Essentially, when the user logs into a web site and enters some information, the server assigns the user a 32 character, random, session ID which uniquely identifies the user. It stores this ID on the users computer as a cookie, along with time-out expiration information. Any additional sensitive user information, like the quantity, and item number in the shopping cart, or a credit card number is stored on the server, along with that particular user’s session ID.

I don’t have enough space in this post to go through all the details on how sessions are configured. The “php.ini” file currently contains 24 different session variables that can be set concerning sessions security, session expiration, where sessions will be stored on the server, what to do if the user disabled his cookies, and whether a session should be started automatically when a user arrives on a site. I will cover these in more detail in my next post. Usually the default configuration when you first install PHP is adequate. For now, let’s concentrate on using session to store variables between web pages.

To start a session you call session_start() at the top of the web page file, before anything else. Since your storing the session ID in a cookie, session_start has to be called before any new line in the web page file, please see my cookies post for an explanation. When session_start() is called PHP checks to see if a session has already been started, and if it hasn’t, it will assign that user a session ID and store it in a cookie. It also sets up a unique global session array on the server, identified by, you guessed it, the session ID.

PHP keeps session variables in a $_SESSION[] array. This array is available globally, which means it doesn’t matter which page of the web server application you go to, the information will be available, which is what we want.

To store information in a session that you can use in your application, or specific user information, you do the following:

session_start();
$_SESSION['firstname'] = $fname ;
$_SESSION['lastname'] = $lname ;
$_SESSION['usercity'] = $city ;
$_SESSION['address'] = $addr ;

That’s it. You now have firstname, lastname, usercity, and address available to you on any web page in your application. Notice that the information is stored in an associative $_SESSION array. To retrieve this information on another page, we do the reverse, at the top of the file, like so:

session_start();
$fname = $_SESSION['firstname'] ;
$lname = $_SESSION['lastname'] ;
$city = $_SESSION['usercity'] ;
$address = $_SESSION['address'] ;

We have to start the session again on the page where you want to retrieve the session information. This will retrieve the session ID from the cookie on the user’s computer, and using that session ID, connect to the $_SESSION array for that particular user.

If cookies are disabled the session ID will be retrieved from information in the web URL. If sensitive user information is being stored, certainly an https encrypted connection should be used to prevent user information from being compromised.

Session variables are common in web applications, and are used frequently, especially internally, within a web application to pass variables from one page to another.

Session Varaibles – Moving inside your Application – An introduction

Posted by dale | PHP | Saturday 27 February 2010 7:34 pm

Our focus for this series of postings has been on the problems associated with getting information from one page to another in a stateless, Internet environment, where nothing is saved from one web page to the next. How do we pass the items you want to purchase from the form submission page to the shopping cart web page, for example.

To this point, we’ve covered passing user generated information to the server with forms using GET and POST, and how to use cookies to store temporary information on the user’s computer. These all involved, to some extent, user interaction.

We now will move on to passing data, variables, around the various files in your web application. This assumes you’ve obtained information from the user with a post, or get, or a cookie, or a call to the database, and have assigned that snippet of information to a variable name, like this:

//using the form GET method
$fname = $_GET['firstname'];

// using the form POST method
$lname = $_POST['lastname'];

// using cookie information
$city = $_COOKIE['usercity'];

// using a function to call the information from the database
$addr = getaddr( $username );

We’ll focus on taking variables, in this example: $fname, $lname, $city, or $addr to the next PHP file on the server, you’ll use to either display the variable, or use the variable in your application. Since php is a scripting, or interpretive language, when you open up a new file it stands on its own, and any data, or variables you’ll need, will have to be explicitly passed to that file. How we do that will be the subject of the next series of posts.

Since most modern languages use object-oriented software, and PHP, is no exception, we will eventually get to passing entire objects to other files and ways to persist objects in your application, but let’s not get ahead of ourselves, we’ll start with sessions and passing information with a session variable.

Opera and Firefox release new Browser Versions – a Review

Posted by dale | Browsers,Software | Friday 12 February 2010 6:02 pm

Opera has just released version 10.10, today, and Firefox recently released version 3.6. Currently of the popular browsers, Chrome is the fastest, followed very, very closely by Opera, and Safari, with Firefox coming before Internet Explorer, but way back from the rest.

Chrome is fast, but the interface is different with its top line tabs and Omnibox combined search and browser address window. It takes getting use to, and I have not been using it, because it was not stable initially.

Internet Explorer is way behind in browser compatibility and speed, and is an after thought in my mind. When and if Microsoft ever gets up to W3C standards, decides to use web standards for determining box widths instead of their proprietary method, and passes the ACID3 test, I might consider it, but not before.

Safari is fast, and it looks nice, but they do this by pumping up the luminance or gamma of their colors from all the other web browser colors, so the browser colors look sharper. Unfortunately, I can’t use their colors system for development when I’m building for all browsers. I’ll leave the Safari browser to Mac Users.

Which brings us to Firefox and Opera. I use Firefox about 70% of the time, mostly because of its web development plugin tools. There are three plugins I recommend for web development: Aardvark, Firebug, and Web Developer. I use all three. This makes Firefox unique as no other browser has these tools. Consequently, it is my web development browser of choice. Yes it loads slow as molasses, but everything runs fine once its up. I had to wait until the Aardvark plugin was ready, but now I’m up and running on 3.6.

What’s with 3.6? Firefox claims speed improvements in page loads, and it looks like this is true, it’s much faster loading both pages and booting, but still doesn’t seem up to the other fast browsers. Last release Firefox reached a 93 on the Acid 3 test, but rather jerkily. It now reaches 94 smoothly, still not 100. You now have type ahead in the address bar, which they call the “Awesome Bar.” Just start typing the site name and possible sites are gradually filtered to give you the correct URL. This is a rip off of the Chrome Omnibox, but there search capability is limited compared to Chrome. You now have one click bookmarks by clicking the star in the “Awesome Bar” window, and there are bookmark tags, like Delicious. Type a tag in the “Awesome Bar” and all your tagged items URL populate. This does not yet synchronize with your other Firefox browsers. They now have a Private Browsing option you can toggle. I’m skeptical of this, as Google keeps a complete record of all your browsing and your searches in its database. For looks, they have 35,000 personas which changes the look of the browser, to me this is just fluff.

And now to my favorite browser, Opera with its new 10.10 release. Opera is fast, and looks great. Only about 2% of the population uses it, so there is very little problem with malware, or virus attacks. It’s safe, secure, meets W3C standards, and passes ACID 3 quickly with flying colors. It’s a great browser. If it had the Internet tools of Firefox, I’d never look back and use Opera full time.

With Version 10.10 Opera claims five things that you can only do in Opera: Application sharing of data with others, compress web pages to load pages faster for people with slow data connections, visual tabs where you see a thumbnail of the web page, in addition to the text tag of the tab like in other browsers; customize your web page thumbnails in the speed dial window, synchronize your tabs, bookmarks, and other data with your other Opera browsers over the Internet. This is like Delicious in its synchronizing. Opera also has integrated themes for looks, and an integrated Opera mail program, although I admit, I prefer Thunderbird at the moment.

If you’re a die-hard Firefox user, you’ll like the improved Firefox speed and tags with the Awesome bar. If your not into web development, I highly recommend you download Opera and give it a test drive, check out the speed, convenient surfing tools, and overall good looks. Change the appearance in tools->appearance, drag the tag bar down to see the visual tabs, and enjoy Opera.

Passing Variables – PHP Cookies

Posted by dale | Browsers,PHP,XHTML | Saturday 6 February 2010 12:29 pm

Before we set some cookies, let’s look at the flow of messages and responses between your computer, and the server, where the web pages are stored. When you click on a link to go to a web site, your browser sends a “HTTP Header” request to the server for that web page. The Header message is variable in length and can get lengthy. The browser sends the HTTP Header, then waits for the server to send a “response header,” followed by the web page. How does the server know that the browser’s Header message is complete so it can respond? A blank line is sent at the end of the HTTP Header. The server when seeing the blank line responds with a “response header,” before passing the page.

Why am I going through this? Because the event that passes the communication baton from browser to server, and back again is a “blank line.” When you pass a cookie to a browser, it is attached to the server’s “response header”, but if a blank line shows up in the web page, before you tell the server to attach the cookie to the response header, you’ll get an error message, something like, “Warning cannot modify header information – headers already sent...” In other words, your command came late, the headers already gone. This can drive you nuts trying to figure out where the bug is in your code, if your not aware of what’s happening. The first thing you want to avoid is a blank line, or even a space at the top of the file before the PHP start tag.

The first step in setting a cookie is to tell the server to attach the cookie to its response header. This is done at the very top of the web page, before any blank lines, or “HTML” or “head” tags, with PHP’s “setcookie” function, like this:

<?php
setcookie( 'message_1', 'I am loaded and ready for bear');
?>

The “setcookie” function can take up to six parameters:

1. “Name”, the name of the cookie, a string, in this case: ‘message_1′ ;

2. “Value”, the value of the cookie, can be a string or number, in this case: ‘I am loaded and ready for bear’ ;

3. “Expire”, when the cookie should expire on the user’s browser. This is expressed in seconds, in linux system time based on seconds since January 1, 1970. I suggest you use a PHP time function, and add to it the number of seconds you’d like the cookie to be active in the browser, or use the browser default, since I’m using Firefox, the browser default is 90 days;

4. “Path”, the path on the server where the cookie will be made available. There’s a lot of files on the server, default is the current path;

5. “Domain”, the domain or url for which the cookie will be available. If you have multiple servers serving pages, on which server will cookie information be made available. The default is the current server.;

6. “Secure”, if you only want the cookie to be sent over a secure connection, like “https://”, set it to “1,” if it’s to be secured, the default is “0,” not secure.

Cookies exist in pairs, a name of the cookie, and its value. The other four parameters are usually not sent, the defaults are used. Normally, only two parameters are passed, name and value.

When your browser receives the cookie from the server it stores it in a set file location on your computer, depending on the browser. When you access that web site again, the browser, if there is a cookie available for that web site, attaches to to the HTTP Header it sends to the server. Cookies are a two-step process, you send it first to set the cookie, and then to get the cookie back you have to ask for the page again.

Ok, we’ve set the cookie in the first response header from the server, how do we get the cookie back from the browser. Well, the cookie, when it comes back, is attached to the HTTP Header, how do we read it? Assuming you’ve refreshed your browser, or asked for the page again. Here’s a block of code to do just that,

// Always check to see if the cookie exists,
// or was not deleted by the user
if (isset($_COOKIE['message_1'])){

   echo "The cookie is loaded: " . $_COOKIE['message_1'] ;
}

If the cookie exists and is set, this will echo: “The cookie is loaded: I am loaded and ready for bear

You also can set cookies in an array. Here’s an example with the cookie’s expiration time set to 10 days :

setcookie ( "myarray[one]" , "My " , time()+ 60*60*24+10 );
setcookie ( "myarray[two])" , "Funny " , time()+ 60*60*24+10 );
setcookie ( "myarray[three]" , "Valentine ", time()+ 60*60*24+10 );

To retrieve this array, we use a loop thus:

if ( isset($_COOKIE['myarray']) ) {
   foreach ( $_COOKIE['myarray'] as $note ) {
      echo $note ;
   }
}

And the output is: “My Funny Valentine“. And finally you can change a cookies value by calling setcookie() again, or delete the cookie by specifying a time in the past, thus: setcookie( “x”, “” , time() – 3600 ) will delete the cookie.

I mentioned cookies are public. Although, you can not look at them directly with a regular text editor, like notepad, and they can be encrypted, there are cookie management editors you can download to read cookies, and there are TCP/IP tools that you can use to watch the traffic go back and forth to a web site including the cookies with their names and values. Cookies can be useful, just be careful how you use them, and what information you store in them.

Next Page »