Wednesday, August 17, 2011

Browser Caching

Why do I always get the wrong page?

By default, the most recent versions of Internet Explorer and Mozzila based browsers like Firfox will give you the old page, until a newer page becomes available. If you just bought a new computer, then you should familiarize yourself with the settings in Tools and Internet options.

If your browser settings are not configured properly, then you may never know what your looking at. There are several settings in your browser to configure the way pages are cached on your computer.

When you visit a website, the page you are viewing is stored to your computer. Depending on your settings, the next time you visit the site, your browser will bring up the page stored on your computer (c ache).

To ensure that you are looking at the latest copy of a page, you should configure your browser settings to get the latest page, every time it is reloaded. In Internet Explorer go to Tools and Internet Options. Click The click browser history and settings. Click the settings, “Every time I visit the web page“. Thats all you need to do for Internet Explorer. The next time you visit a website, you will get the latest copy of the page. It is especially important when viewing websites with dynamic content.

In Firefox it is a bit more difficult. Open a browser window and enter about:config, then hit enter. A window will come up and ask you if you are sure that you want to proceed. Just click okay, and look for the line called, browser.cache.check_doc_frequency. Change it from 3 to 1, and close the window.

For future reference:

0 – Check for a new version of a page once per session (a session starts when the first application window opens and ends when the last application window closes).

1 - Check for a new version every time a page is loaded.

2 – Never check for a new version – always load the page from cache.

3- Check for a new version when the page is out of date. (Default)


To avoid frustration, and undue aggravation, especially when designing and building your own websites; always make sure you check your browser settings to ensure that you are getting the most recent copy of the site you are viewing.


Introducing: Backup Smart



Protect Your Online Business And Keep All Of Your Data Safe And Secure On Your Local Hard Drive!

Works With Windows, Mac OSX, and Linux and Available In Multiple Languages


Click here to order.

Wednesday, July 20, 2011

MySql Variables

It is very time consuming to copy and paste required parameters into every script. To save time create a class called mysql.php to store all the information for your database in one central location.

You can store usernames, passwords, and table names, and easily access them from any script.

In ASP.net it is very easy, database parameters are stored and accessed from one central place; however, PHP is different. There is really no central configuration file.

The best way to deal with this is to create a generic class that you can use anywhere. Here is an example of a generic database class;



class mysql_data
{

//** Configure connection to database.

public $host = "Your database server name.";
public $username= "username";
public $password= "password";
public $dbid="Enter your database name here.";

//** List all tables you are using.

public $tbl1="Buy"; // Table name 1
public $tbl2="Company"; // Table name 2

//*** List any select statements used.

// constructor
public function __construct() {
//Do not initialize anything.
}

}



Call the class using; require 'mysql_conf.php'. It should be the first line in your script. Then setup a pointer to the class, $mysql_class_object = new mysql_data; //Declare pointer to sql class.

After configuring a pointer to your class, you need to setup your variables to access the public variable names in your class object. Use this format.


//Setup variables for our class object. (To access public variables you must setup another variable.)

$host=host;
$dbid=dbid;
$user=username;
$pass=password;
$table1=tbl1; //Buy
$table2=tbl2; //Company


//*****************

To start use the variable names you setup, you must use this format;

$our_host=$mysql_class_object->$host;

See the php manual for further info on public variables, http://php.net/manual/en/language.oop5.php.


You can create generic class objects for almost anything you routinely do in php. By building up a library of class objects, you can speed up your development time, and cut down on errors. When creating a class object keep in mind the following;

1) Re-usability

Plan your class well. Think about what your using it for. After you create the class you should not need to modify it for any application.

2) Applications

Where is the class object going to be used in the future. It is important to understand where you are going to use the class object in your future projects. You want to keep things simple, and not go on a rampage, creating a hundred useless class libraries that you hardly use. Think about things that you do routinely from project to project, like updating a table in a database.

Simple is best. Don't over complicate. The more code you write, the longer it takes you to finish a project, and the more frustrating it makes it for anyone else who has to go through your code.

Master the basics of Photoshop. Step buy step video's reveal shortcuts on how to master Photoshop quickly and easily. In just two hours, learn how to create graphics quickly, easily and stress free.

Order, Learn Photoshop Now. Visit learnphotoshopnow.com.


Tuesday, July 5, 2011

Templates

Templates are time consuming to create, but will save time in the long run if put together properly.

When doing your templates consider what you usually put into a web site that your doing.

Are you making allot of contact forms, edit screens, screens with different layouts? Are you using the same functions over and over again on different projects? Are you using the same field names over and over again, like street, city, name ecetera?

Create a folder called templates, and slowly add to it over time. It takes time and effort to create everything, but in the end it will save allot of time and frustration.

I would recommend that you start of with a couple of page templates for the visitor, then add a contact form, an edit screen, a login page with everything necessary to login to a content management area.

Slowly build up a list of html pages, javascript class objects, php classes, style sheets, and navagation buttons. While putting together your generic templates, think about how your going to use them. Everything should be reusable in one way or the other.

Dividers should be used whenever possible. They keep everything in proper alignment, load faster, and are compatible with most browsers.

When constructing your generic style sheet plan short and long dividers, and incorporate dividers with columns.

Columns are tricky. The basic setup for a column is an outside and inside divider. There can never just be one column unless the outside divider is equal to the inside divider; otherwise, you must add empty columns to fill out the rest of the space in the outside divider. (it may be possible to use padding).

Class objects should be used to put together like functions. They can be accessed via a single function with a parameter. For example;

bind (parm){

pnt = new operations();

if (parm="moverecords"){
pnt.moverecords();
}

}

It is a good idea to keep your form fields the same. A good way to do this is to setup a class with variables pointing to page objects, like;

address = document.getElement[txt_address].value;

Be careful. Always check to see if the object exists on the page before using it.

If your using Ajax, separate your Ajax functions into a separate file. Keep them as functions. Don't try to get fancy. There aren't too many of them, and it isn't worth the time or effort. The only thing you may want to do is to consolidate your if statements into a case structure.

Setting up all these templates can be time consuming in the beginning, but will save you time and money in the end.

Monday, May 9, 2011

Web Server Codes

Web server codes are sent by a web server to indicate what is happening. It is useful to understand these codes when configuring a web site.

This is some information I found while researching the 403 error code. Visit, Wikipedia for details.

Allot of times when coding a website, you will come across these codes, and you need to understand them.

Some programming routines will not work unless they are coded a particular way; otherwise, you will get a strange code from the web server.

Tuesday, May 3, 2011

Planning for the Future

When writing javascript classes think about what functionality you use most often. Allot of functions can be reused, and will speed development time by packaging them into a class object.

If you are just starting out it may be tough to get your head around javascript classes, but they really aren't that difficult. See my previous blogs about javascript classes.

Form fields are one of the many things that can be packaged and reused. Just check each object to see if it exists on the page, before declaring it, otherwise the browser will object. Functions like one used to get a parameter from an url, or to change the properties of an object on the page can also be packaged.

If you are not using classes, and you are just adding functions to your javascript file as needed, you will eventually run into a rat's nest. The more code you add, the more complicated it gets, and it takes longer and longer to track down a problem.

Some of my projects have javascript files of over 1000 lines of code, and I am now using classes to try and simplify my coding, and make it easier to find things. If you need help, there are lots of places you can go on the Internet to find information about coding javascript classes.

One think to remember is that you must call a method via a function, and you can not just declare a reference to the object you are using.

If you try to declare a public reference to the object, IE will accept it and Mozilla browsers won't. I just use a function called bind with a bunch of case statements to evaluate a parameter, and call the appropriate method.

Packaging up your functions makes allot of sense, especially on projects that use allot of dynamic data. Most websites you design will probably need allot of special functionality to access data, and will add up.

If you put everything into classes, and someone has to go through your code, then they will be able to understand it just as well as you.

Programming for the Web