Archive for the ‘Tech’ Category

Getting started with IIS part 2

Sunday, September 16th, 2007 | Life, Tech

Make sure you read part I before enbarking on this second entry. For those of you who have read part I and are wondering what do I do next? Read on…

Virtual Directories

That is everything you need to know for customising the root directory. But that’s just the properties options. Next we are going to create a directory so that the folder ‘work’ will be mapped to a completely different directory. First close the properties box and bring to focus the Management Console if it isn’t already. Then find the root icon again. Now right click it and hover over the new > link. This should bring up a new link with an option that says ‘virtual directory.’ Click it and wait for the wizard to open.

Click next to skip past the welcome screen and you will be greeted with a box asking you to select an alias. This is simply a name for the directory which will be used. In this example we are using ‘work’ so write work into the box and click next. This means that it will be accessed from http://locahost/work. Next we are asked for a directory. If this is going to be a redirect then just add any directory and change it later. However if say you wanted to map this to My Documents then click browse and find My Documents. Click it and then click OK. The path will then be entered into the box for you.

Now click next again and you will be brought to the permissions screen. This is where you set the permissions and what can happen. Normally you can just click next again to pass it but this time check the box which says browse. Now click next again and finally click the finish button on the next screen to close the wizard. The directory has been created and can be seen on the list as a branch of ‘root.’

Now its time to test the new directory – open up your browser and point it to http://localhost/work so that the page loads up. This should, if you have done it correctly, bring up a list of all the files in you’re my Documents folder. Congratulations if it worked you have a virtual directory. If not then make sure you can find the directory under root and make sure the path to My Documents is correct.

Next go back to the Management Console and click root on the left. This should bring up a list of all the files and virtual directories on the right in the big box. In this box you should now find ‘work’ next to a little grey box icon. Right click on it and click properties. This will bring up a properties box named after the virtual directory.

The default selected tab on here is Virtual Directory. This basically does the same job as the Home Directory tab when we had the properties page for root on screen. The other tabs also match up to the tabs on the root properties although there are not as many as you do not have the settings for the entire site on top of the directory settings like you do when you are editing the properties of the root site.

Redirects

Finally I want to cover one more thing – setting up a virtual directory to do a redirect. To do this select Virtual Directory from the list of tabs in the properties for ‘work’ and find ‘a redirect to a URL’ from the list of bullet options at the top. Click this and all the directory information disappears to make way for redirect information.

The top box is where you enter a URL for it to redirect to. This can be a virtual directory on your computer although you cannot redirect it straight to a file. So if you wanted to link it to something in your unzipped folder on your hard drive you would have to set up a virtual directory which is set to your unzipped folder.

Here is my example. I have my directory http://localhost/work/ and the redirection URL I have entered is http://www.mworld.us/entertainment/fake.asp. If I enter this URL and don’t tick any boxes, when I enter in the address to my directory it will be replaced in the address bar by the direct URL which will go to the exact address I entered – and in this case bring up a 404 error page seen as the address is not real. The same happens if I have the box ticked saying ‘the exact URL entered above.’

However if I tick the box ‘a directory below this one’ the directory will remain in the will remain in the address bar as if it is the original directory. So I could reduce the address of http://localhost/files/folders/stuff/complext/somefile.php? variable1=somevalue&variable2=othervalue to http://localhost/somefile and it would display the same file but users would see http://localhost/somefile in their browsers.

The final tick box is ‘a permanent redirect for this resource,’ Normally redirects such as the above are temporary as the file is still in the other location and you are just masking it However if the file has moved and you want to set up a redirect to another location so your users can find it, that is when you tick the box to say – never come back to this redirect address, always use the address its redirecting to.

Final Tasks

Right, that’s done. If you don’t want that directory hanging around any more then close the properties window if it is still active and find the directory in the list in the Management Console. Then right click its name and click delete to remove it.

There is one more important thing which you will probably use when using Internet Information services. That is stopping and starting your website. If you click root again in the tree view on the left you will notice three black buttons at the top become click able. These allow you to stop, start and pause your web server. The web server only works when it is running. So if you don’t want it running then click stop. Click start again when you want to reactivate it. This is useful when your server stops delivery pages because it’s moaning of ‘heavy traffic.’ If this is the case click stop, pause for a second or two then click start again.

Conclusion

Hopefully this should get you started with the basics of internet information services. There is lots of fun to be had experimenting and playing about with the different settings so my advice is just have fun and see what you can do.

Getting started with IIS part 1

Sunday, September 16th, 2007 | Life, Tech

Internet Information Services is by far the most popular server for Windows; and not without good reason. Personally I do not know what the people who recon Apache is more configurable are on about. They should really take a look at the properties page of a website on IIS. But complaining about them is another story; we are fear to get to grips with IIS.

For those of you with Windows Server 2003 you will have IIS 6.0. However seen as anyone with Windows Server 2003 will know that they are doing anyway and most users will have Windows XP or 2000, I am going to use IIS 5.1 as my model. This should cover most versions fine anyway as the interface changes have not been radical to the best of my knowledge.

Introduction

The key to management of IIS is the Management Console. This will have a toolbar along the top, a tree view on the left and a files list on the right at the bottom which is the main section. As standard when you open it in the tree view you get Internet Information Servers with the name of your computer in a branch. In a branch of your local computer you will then have Web Sites, below that FTP sites if you have added that on although it’s not installed as default and finally Default SMTP Virtual Server.

If you don’t see this then click the box with the plus in on the left of them to expand them so that you can. The next thing to do is to do the same so you can see a list of your websites. There should only be one unless you’re running a Windows 2000 Server. The one that does exist is called root. This is your default website so let’s start configuring it to your settings. Right click on it and click properties.

Customising

This will bring up the properties box with root properties at the top and no less than eight different tabs full of settings for you to configure the website. The first section of the already selected ‘website’ tab is how the site is identified. Leave the description as root. As next one, IP addresses allows you to specify different IP addresses for different sites although one you will only have one IP address most likely and two all IP addresses go to the root folder by default anyway. So seen as we do not have multiple websites this is not a problem.

The connections box is something that can be left alone. Although if you are having problems with time outs and pages not loading you may want to play about with the seconds before timeout. Below that is the box which enables server logging. I always find these useful and use the standard W3C format to log activity in a file.

Next up click the ‘ISAPI Filters’ tab. You will probably end up with a blank list with a few buttons. This is where you can install, enable and disable ISAPI filters. An ISAPI filter is a program that responds to events during the processing of an HTTP request. In other words special executable scripts that do things when a page is requested. An example of this is PHP although there are other ways to use PHP. But as an example, when a page is requested the ISAPI filter responds and sorts out the PHP code delivering HTML to the user.

Next click the ‘home directory’ tab. This gives information on where the files are on your computer. The top box gives you three options about where the files are. Even the directory should lead to a folder on this computer, the directory should lead to a folder on a network computer or it should redirect to a different address. The first two allow you to choose a file path, the first starting with drive:\ and the second starting with a network path.

These first two options also have tick boxes about what can be run and what cannot. Read just allows users to access and view files so keep this one ticked. Log visits and index this resource should remain at their default. Directory browsing means that users get a list of the files in the directory which they can click on to visit. Sometimes this is useful but if you don’t want visitors getting a full list of all the files then don’t tick it. Finally write allows files such as text files, databases, or anything else you want scripts to be able to add data to, to be changed.

Generally the application settings below this can be ignored too. The only one you may want to change is the application permissions allowing you to disable all scripts or allow scripts and executables. Or have a happy mix between. I always leave this at default although if you want to run some executables then you may want to disable them or if users can upload scripts to this directory you may want to disable this.

Next up is the ‘documents’ tab. This one controls the list of documents that are delivered as the default document of a folder if no file name is specified. You can add as many different possible file names as you want to this box by clicking add and typing the file name including the extension in such as home.html. You then order them as you want as the higher they are the higher priority they have. A have several in mine:

Index.asp
Index.php
Index.htm
Default.asp
Default.php
Default.htm
Index.html
Default.html
Iisstart.asp

This enables me to use all the standard file names for different sites and the homepage will still be delivered as the default document. Iisstart.asp is a default one added in by IIS as if no other documents are present you will be taken to an introduction page when you first point your browser to IIS before you have set it up. You can remove that one if you wish.

The other option under this tab is document footer. This enables you to have a footer document served up at the bottom of every page. This may be useful say for a free web hosting company who wishes to add an advert or link to their homepage to the bottom of every page. Or even if you wanted to include a navigation link but didn’t want to have to update every page when you added or changed a link.

We are getting deeper now and beyond the standard options you are likely to use. But I will give a quick overview of what else can be done too in the properties window. The next tab is ‘directory security.’ This enables you to have secure communications, restrict websites and IP addresses and others.

The ‘HTTP Headers’ allows you to set how often pages expire. If your content is only updated say every 5 minutes or for instance if you only want new messages posted in a guest book to be updated every 5 minutes then you can set it so pages in this directory are only refreshed every 5 minutes. A new page will be generated every 5 minutes and this version will be delivered from the cache until the next update.

‘Custom errors’ allow you to direct users to different pages depending on what error happens. For example if you wanted to send them to a personalised error page when a page cannot be found with a dancing Jesus saying “this page does not exist’ then you would click 404 and then click edit properties. You could then choose the custom file.

Finally ‘Server Extensions’ allows you to enable use of authoring such as Front Page change version control and performance and specify settings for things such as emails and security settings. Luckily if you get stuck there is a help button at the bottom of the properties window ;).

Configuring PWS (Microsoft Personal Web Server)

Sunday, September 16th, 2007 | Life, Tech

Personal Web Server is pretty easy to configure. Even back in 1995 when it was all web based. However in this article I am looking at the PWS version which was shipped with Windows 98 and ME software.

The basic’s to it are very simply. In fact the only page of options we will be looking at is the advanced page. Open up your personal web server consol from the system tray and click advanced down the left hand side.

You should now be presented with a tree like view with the top root document and several sub folders. From here you can add virtual directories. Virtual directories are directories which aren’t really there but are instead linked to it.

For instance if you had two directories, your main website root C:\websites and a downloads directory which you wanted to be on your server at C:\downloads. Obviously you don’t want the move this folder into your other folder. And so you create a virtual directory so that http://localhost/downloads goes to C:\downloads rather than C:\websites\downloads.

Beware: Virtual directories override physical (normal) directories. So if you had both a virtual directory called downloads and a folder in your website root called downloads, the virtual directory would be used instead of the folder when using hyperlinks, etc.

In PWS you can create as many virtual directories as you like. Click add below the list of directories. You can also add virtual directories within virtual directories so you could set up http://localhost/downloads/games to go to C:\games rather than C:\downloads\games. To do this click on the downloads virtual directory before clicking new, rather than click the root directory and then clicking new.

You can change the properties of each of the directories including the root directory by clicking it and then click properties. Here you will probably be presented with a name for the directory (unless it is the root) as well as the file path to the directory.

You also have 3 tick boxes. Read which allows people to read the files in the server. You will almost always want to keep this ticked. The second one is script which allows the web server to run scripts. This is another one you will want to keep ticked.

The final one is write. This allows files such as text files and databases to have data added and removed this one. It’s a good idea to keep this one ticked if its your own server so you can run scripts such as ones that change database’s and is required if you want to alter any files.

There are also a few options on the main page of the advanced section at the bottom. One of these is “allow directory browsing.” This means that if a user goes to a folder, for example http://localhost, they will be presented with a list of the files and folders in the directory which they can click on.

Default document allows a file to be served as a kind of homepage when a user goes to a directory. For example if your default document file name was home.htm, when a user went to http://localhost, they would get home.htm if it existed.

The standards for default documents are default and index in which you should list several file formats. I use .asp .htm and .html though if you use other formats such as php and cfm you should list these too.

Conclusion

Personal Web Server has quite a few customisation options for each directory as well as the entire site and despite its problems with not being able to cope with high traffic or indeed anything above very little traffic, makes a great testing server especially for active server page developers.

HTML to AnyCode review

Sunday, September 16th, 2007 | Life, Tech

Shareware was never one of my favourite groups of software because I always had to find a new replacement application when the 15 day trial expired. Occasionally though a piece of software comes along which seems indispensable and even the guy who hasn’t paid for the last dozen pieces of software he has got, despite the fact he should, we shell out for a good bit of shareware.

Why? Because some applications really are good. The piece of software that got my digging deep (although it’s a phase seen as shareware is almost always very well priced) was Exactcom’s HTML to AnyCode Converter. Allowing you to insert HTML click a button and have it translated into a different language without all the complications of you having to work out how to change and update it as well as risking missing something and causing your new script to go horribly wrong.

It’s a very simple application, once launched it has a title image and 3 tabs below this in which control all its function. Clicking the first tab allows you to enter your code and the language you want it to be converted to. You can also load in a source file in which will then automatically populate the code box for you – just in case you are too lazy to cut and paste; a problem which often haunts me.

One click on the convert button and suddenly your code has been transformed into the language of your choice, the default being JavaScript. The code is even wrapped in <script> tags so you can copy and paste straight into your page. These are automatically removed if you save the file so you can immediately include it into your page.

A nice help tabs also backs up the application with some information on how to use the application, how to register it, about Exactcom and contact details if you are having any problems with it – their support is good too. There is a final tab for registering the application though this disappears once done.

Although the default pages which the open file looks for are .htm and .html, all formats can be selected and imported. The code is rich text too so all your code is fully colour coded – it might be the next step up from Notepad as a web editor. It seems that they have thought of everything!

The only one complaint I would have against it is the image at the top still has a big “Buy it now!” slogan on despite the fact that I purchased and registered it many moons ago. That’s not really a problem though and if they happen to change it in later versions; I have free upgrades for life so I am not worried. Free upgrades are another good reason for shareware – most applications come with it.

Twice I have asked them for support and both times I got a prompt response. The first was when I lost my registration code (wasn’t my fault, well, maybe a little bit) and the second time was one of their new versions had an error in the JavaScript output, which the solved and made a new version available in around a day. Should you be worried that there was an error? I don’t think so, after all its shareware not a huge corporate developing the software, and free upgrades mean all bug fixes are yours.

Though its functions are not huge I find them very useful – I have used it for around a year now and I have hardy ever used it for anything other than converting my HTML text into JavaScript – long story which I will tell shortly. I have hardy scratched the surface of the conversions to ASP, PHP, Perl and JSP.

My main use for the application is for stories on one of my websites. Back in the olden days when I was getting started with Microsoft Access I did not know how to fit all my HTML in a text field with a maximum character amount of 255 – luckily for Exactcom I had not discovered the memo field type and so my solution was to convert the stories into JavaScript, give them a file named based on their ID in the database and include them dynamically that way.

That made HTML to AnyCode Converter vital to my operation though – but that doesn’t make it vital to yours. Exactcom make some great software and HTML to AnyCode is the best converter around. But the use of converting code is not a wide market. Overall, if you need converting done then this software is the only buy. But if you don’t need this function then it’s a product you will sadly not want to register.

Creating water textures in Photoshop

Sunday, September 16th, 2007 | Life, Tech

Requirements: Adobe Photoshop 7

You can proably do this with older version of photoshop but if you don’t have them or want the new version, you can download a 30 day trail.

Introduction

In this article I’m going to show you how to create a water texture in Photoshop. Although Macromedia Fireworks has some built in textures to do this, the textures you can create in Photoshop look far more realistic and is more customizable. For more infromation on image editing see my last column.

I will also make it seemless so you can tile it on your web page, background, etc as wallpaper and it won’t show the lines where the image repeats.

Step by step

1. The first thing to do is to create a new image 400 x 300 pixels. This is just my recommended size though, the size of the document is irrelevant.

2. You’ll need a layer to work with. If you don’t already have one (you probably will) then create a new one.

3. Hit D to set your colors to default: black as foreground and white as background. Go to Filter>Render>Clouds to make what will be the base of our water texture.

4. Go to Filter>Blur>Radial Blur and use these settings – Amount: 38, Blur Method: Spin, Quality: Good (unless you don’t mind waiting a little bit, in that case choose Best). Then go to Filter>Blur>Gaussian Blur with a radius of 2 because we want this to be blurry to the max.

5. Go to Filter>Sketch>Bas Relief and choose the settings – Detail: 13, Smoothness 10. Next go to Filter>Sketch>Chrome and select the following options – Detail: 5, Smoothness 2.

6. Now to add color. Duplicate the layer by going to the Layers palette and dragging the layer with the water texture onto. Click on the eyeball to the left of the new layer you just made to hide it. Select the original (lower) layer and go to Image>Adjust>Channel Mixer. You may want to make it a different color, but to copy the blue I used make these changes – in the Red Output Channel move the blue to the left; in the Green Output Channel move the green slightly to the right; in the Blue Output Channel move the blue to the right. Next click on the at the top of the layers palette and choose New Adjustment Layer. Then choose Hue/Saturation as the type. Play around with the Hue and the Saturation bars until the blue color looks the way you like it.

7. Now click the upper layer in the Layers palette. In the left drop-down box change Normal to Color Dodge and lower the Opacity real low to about 5-10%. (This layer brightens the lightest areas of the image and makes them glow a little). As a final touch you may want to adjust the Hue/Saturation layer again (just double click it) or try adjusting the Curves of the lowest layer (click it and hit Ctrl/M).

8. First make sure you save your file. Then flatten your layers by going Layer>Flatten Image. Next go Filter>Other>Offset. Fill in the coordinates – Horizontal: 200, Vertical: 200. After that, go Filter>Distort>Twirl select 120° as the angle. Now you may be done here if you like the way it looks, but I had a poor turn out on this example – the four sections were still clearly visible. So to correct this simply add one more filter. Go Filter>Distort>ZigZag and choose – Amount: 10, Ridges: 5, Pond Ripples.

9. Just for fun, you may want to see your image in seamless-tiling glory. Hit Ctrl/A to select all, then go to Edit>Define Pattern. Create a new image (about 800×800 pixels), click the paint bucket, set Contents to Pattern in the Options palette, and click in your blank image.

SQL UPDATE command

Sunday, September 16th, 2007 | Life, Tech

The SQL update command allows you to make specific changes to one or more rows. You could in theory do this by deleting the old one and inserting a new one but this means you have to deal with all the data and can only do one row of data. Using UPDATE solves both of these problems.

Basic syntax

As with everything there is a basic command structure to allow you to sort out what you want and run the various different parts of the commands. The syntax for using UPDATE is as follows:

UPDATE table SET field1 = 'value1', field2 = somenumber WHERE field3 = 'value3'

There are three parts to this. The first is the table to update. The second is the values which you are setting. The third is the validation of which rows in the table should have the update run.

Sample table

To make this easier to do I am going to create a sample table of data from which we can work from. The table is going to be called friends and will have several bits of data in it.

Name	email	age	favourite colour
Jim	jim@mail.com	24	blue
Alex	alex@operamail.com	23	black
Josh	happy@killer.com	30	grey
Mike	mikebob@avril.com	27	blue

Ok first lets say that Josh tells me that his email has changed from happy@killer.com to josh@wiggam.com. So we need to run an update command to change the email address from the old one to the new one.

UPDATE friends SET email = 'josh@wiggam.com' WHERE name = 'Josh'

In this code, all rows where the name is Josh, will have the current email changed to match josh@wiggam.com. This would be a problem if I had two Josh’s but I don’t so only one is updated. If I did have two Josh’s I could change the statement to say:

WHERE email = 'happy@killer.com'

Or I could also try

WHERE name = 'Josh' AND age = 30

Updating multiple values

Next let’s pretend that it’s Alex’s birthday – he turns 24 and decides that his favourite colour is now green. So we need to update two values in the table at once. Luckily this is pretty simple to do.

UPDATE friends SET age = 24, favourite colour = 'green' WHERE name = 'Alex'

First thing I must stress – you should never have a column name with a space it – don’t do it. But seen as this is just an example it’s not a problem. If you really needed a name like that then using FAVOURITE_COLOUR or a dash, etc to space them out.

In the above update statement both age and favourite colour are updated in every row where the name is Alex. Also there are no hyphens around age as it’s a number and so does not require them. You will get an error if you try to put them round a number when using a number column, as you will do for not using them in a text column.

Updating multiple rows

Finally I am going to look at how to update two records at a time. Though we have really already covered it so this is more of a confirmation to make sure you have it right. Take a look at this code:

UPDATE friends SET age = 60 WHERE favourite colour = 'blue'

I decide that everyone who likes blue is an old foogy so I am going to update everyone’s age to 60 who said their favourite colour was blue. As usual the script looks for everyone who is ok by the WHERE validation. This time it finds both Jim and Mike and changes both their ages to 60.

Conclusion

The UPDATE command is fairly simple – you just specify the table to update, the values to set and the conditions a row must meet for the update to be run on that row. One final thought though – take another look at Mike’s email address and try and guess what music I was listening to when I wrote that one :).

Yep, it was of course Feeder ;).

SQL SELECT command

Sunday, September 16th, 2007 | Life, Tech

Whether you connect to MySQL, MS Access, SQL or more databases and whether you do it via PHP, ASP or even more you still use the same basic commands of SQL to extract information from the database.

Below is a sample database table called “members”

Username	Name	Email	Posts
Jim	Jim Harris	jim@ntlworld.com	24
Mod	Toby Hunter	t.hunter@btopenworld.com	4
Happy	Simon Gates	theman2003@aol.com	12

Seen as your database connections and how you phrase the code depends on what language you are using I won’t cover that. Chances are you will have some variable such as db = “your SQL commands here”

First of all, you may want to extract all the data. A basic command would be:

SELECT * FROM members

The SQL commands such as SELECT and FROM are always in capitals. SELECT is the first thing you put whenever you are reading or extracting data. It tells you what to take out. For instance you may only want certain columns.

SELECT name FROM members

Or

SELECT name,email FROM members

* tells the script to take all the columns from the database.

FROM tells you what table in the database to take the data from. So for instance if you had a table called “stats” you would use:

SELECT * FROM stats

Next you may want to add conditionals onto the data to only take certain rows:

SELECT * FROM members WHERE name = "Jim Harris"

This would give you the result:

Jim Jim Harris jim@ntlworld.com 24

You can also add several conditional values on:

SELECT * FROM members WHERE username = "jim" and name = "Jim Harris"

That would produce:

Jim Jim Harris jim@ntlworld.com 24

As with most mathematical type equations you don’t have to use the = sign all the time. For instance:

SELECT * FROM members WHERE posts > 10

This would produce

Jim Jim Harris jim@ntlworld.com 24
Happy Simon Gates theman2003@aol.com 12

The guy with the username “mod” would be missed out as his has not made more than 10 posts.

Finally you can also order the rows. For instance if you wanted to order then by the number of posts they made:

SELECT * FROM members ORDER BY posts DESC

This would produce:

Jim Jim Harris jim@ntlworld.com 24
Happy Simon Gates theman2003@aol.com 12
Mod Toby Hunter t.hunter@btopenworld.com 4

By contrast:

SELECT * FROM members ORDER BY posts ASC

Would produce:

Mod Toby Hunter t.hunter@btopenworld.com 4
Happy Simon Gates theman2003@aol.com 12
Jim Jim Harris jim@ntlworld.com 24

ASC sorted them lowest first or alphabetically and DESC sorts them highest first or reverse alphabetically.

Creating invisible buttons in Flash

Sunday, September 16th, 2007 | Programming, Tech

Sometimes you want to make an area clickable, say part of an image or you have some animation that you do not want to have to convert to a button. What you need is an invisible one.

First draw a square (or whatever shape you want) onto your page. Double click the shapes border and delete it. You don’t need it and it makes the button look weird when you resize it.

Now convert the box into a button. Once you have done this double click it, and add keyframes for up, over, down and hit like you would any normal button.

Go back to the first 3 stages (up, over, down) and delete anything in these frames. The only thing you should leave is the box in the hit keyframe. Now go back to editing the movie (Ctrl + E).

If it worked the button should now appear as a half tranparent blue box. And if it does you have yourself one invisible button. You can now resize this to any area you want it to cover.

Creating a Flash preloader

Sunday, September 16th, 2007 | Programming, Tech

Large movies take a long time to load, especially for users who are not blessed with a high speed broadband connection. Therefore just giving them a screen which says loaded or just giving them nothing at all can leave them a little dazed and wondering what to do. The solution – give them some feedback on what is being loaded.

Movie modifications

The first thing you need to do is have an empty frame at the top. You don’t need anything else – just an empty frame before you content. If it’s easier you could even create a separate scene to house this frame. Make sure it’s a key frame and the next frame where you content begins is a key frame too.

Next create a text box which says loading, or the name of the movie or something similar. This will be our loading object. It should only exist in that first fame. Now with the object selected go to Insert > Convert to Symbol and save it as a movie clip. I recommend the name ‘preloader’ but it has no affect what so ever. It just makes it easier for you to identify it in the library.

The scripting

Now double click on your newly created movie clip and watch it zoom into editing mode. There should currently only be one frame in the timeline now – extend this to three by inserting two new frames. Call this layer text or graphic or something similar. This layer will just remain the normal static text. The scripting will go in a different layer – create a new one for the scripting and make each of the three frames, key frames.

Now we have three key frames in the script layer which we can insert code to. This is expert field so we need expert view on. If you’re not working in expert code view then open the actions panel and click the options view icon. It looks like a little square with an arrow pointing to the top right hand corner. Then click the line which says expert view rather than normal view. This will turn the action scripts window into more of a text editor style window to allow us to insert code.

The first thing we want to do here is to stop the main movie from going any further before it’s loaded. So click on the first frame in the script layer and put the following code in:

_parent.stop();

This tells the main movie to stop. Generally commands like this use the model: object.command. In this example the object is the main movie or _parent as its known and the command is to stop it.

Now click on frame two of the script layer. He we are going to set some variables so we can give the user feedback on how far the movie has loaded so far. We do this by using a few functions built into ActionScript which allow us to get certain values.

kBytesLoaded = getBytesLoaded()/1024;
kBytesTotal = getBytesTotal()/1024;
kBytesRemaining = kBytesTotal - kBytesLoaded;
percentLoaded = 100 * kBytesLoaded / kBytesTotal;
progress = Math.floor(percentLoaded) add "%";

This script works out what has been loaded and how much is to load and then works out the percentage. It’s a great script although I can’t claim responsibility for it. Insert this script into the second frame and that will give us plenty of variables to work with.

Finally click on the third frame in the scripts layer. In here we check to see if the movie has loaded and if it has we send them on their way. If not we continue to loop and give them feedback on what has been loaded so far.

if (percentLoaded < 99){
gotoAndPlay(2);

} else {

_parent.play();
stop();
}

Here you can see if that if less the 99% has loaded then the movie is not fully loaded then the movie clip is sent back to recalculated the variables. If 99% or more has loaded then the movie clip is stopped and the main movie starts again. I use 9% rather than 100% as if there is a little data left which cannot be loaded it will never reach 100% and therefore loop for ever.

Giving feedback

Finally we need to tell the user what is going on. So create a new layer, call it something like feedback. Then insert a text box. This will display the percentage that has been loaded so far. This box needs to be set to dynamic. In Flash MX you can change this in the properties box - look for the drop down menu saying static text and change it to dynamic text.

Also look for the input text box which says var next to it. This stands for variable and will let us make the text box fill with a variable we set. So in the box write:

Progress

This will fill the box with the process variable telling the user what percentage of the movie has loaded. You're done - hit Control + E to return to editing the main movie. You can now export your movie save in the knowledge that users will see how much percentage of the movie has been loaded.

Log your visitors to a text file using PHP

Sunday, September 16th, 2007 | Programming, Tech

Not all web hosts grant access to web server logs. And even if you do have access to them they may not be that useful. The solution is to write your own script which will log your own stats. And it can all be done without the use of a database. Though databases are great for this not everyone has a spare one so I am going to use nothing more complex than a text file to show the information.

The logging file

The first thing we need is a file to record each hit and log the information in a text file. This is done by creating a function and adding all the variables into it. We can then add information for these variables later in the tutorial.

<?php
function logthis ($sessionid, $pagevisited, $ip, $browser, $refer)
{
$log = fopen("log.txt","a");

$countryfile = fopen("http://ip-to-country.com/gert-country/?ip=$ip&user=guest&password=guest","r");
$country = fgets($countryfile,50);
fclose($countryfile);

This sets up the basic information for the log. I also used a tool which allows you to send an IP address and the site will return the country which that user is from. And therefore we can log which country each visitor comes from.

$now = date("d F Y h:i:s A");

fwrite($log,"$now,$sessionid,$pagevisited,$ip,$country,$browser,$refer\n");
$log = fclose($log);

}

?>

This code writes in the information. Well the top bit gets the date. But the second part at least does the interesting things. All the variables are lined up and the data is separated by comma’s to allow it to be analysed later. There is also the \n to indicate a new line should be gone to after the data is written in.

That is all the code for the logging file. Save it as log.php. We are now done with this file so you can close it down as everything else will be done from the other pages.

Code for the pages

For each of the pages you want to log the stats on you need to insert some code above the <html> tag to allow us to track the visitors to that page. So you will probably want to insert the code into all your pages.

There are two parts to the code that needs to be inserted into your pages. The first includes the log.php file into your page so we have the function. The second gives all the information to be included.

<?php

require 'log.php';
session_start();

logthishit(session_id(), $PHP_SELF, $REMOTE_ADDR, $HTTP_USER_AGENT, $HTTP_REFERER);

?>

After the include line there is a line telling PHP to start a session. Sessions are new to PHP4 and allow each user to be treated individually so you can work out when duplicate users are visiting different pages.

This code can be pasted into all your pages and remain relatively unchanged. The only bit which will need some tinkering with is the path to log.php. So for instance if you had a page in a games folder and log.php was in a folder called stats you would need to change log.php next to require to ../stats/log.php.

A few small tasks

You are almost done! Just a few small things to do and then we are finished. First open up your text editor, Notepad is fine, and save a blank file as log.txt in the same folder as you saved log.php. Once that is done upload the two files and any files which you added the code into to your web space.

It’s best to upload your files to the root directory of your website if you can. You then need to make sure that that text file has read and write properties. It may have already although if it doesn’t or your not sure then make sure by right clicking on it in your FTP client and look for a properties menu or something similar. This is usually how it’s accessed though it may vary depending on your FTP client.

Finally there is one more thing you may want to do. If all your files use .htm or a similar extension and you can only run PHP scripts on .php pages you will have a problem as you may not want to rename all the files. So if you can’t rename the pages and PHP scripts don’t work in .htm pages you need to edit your .htaccess file.

If you don’t already have one then you can copy the following code into a blank text file, save it as .htaccess and upload it to your web space. If you already have one then download the current one and add this code or modify the existing code to look like this.

AddType application/x-httpd-php .php .html .htm

You can add any other extensions you use to the end of these too.

Analysis & Conclusion

Now your server log is complete and the script will begin counting all your visitors and saving them in log.txt. When you want to view the log all you have to do is either point your browser to the file or download it using your FTP client and open it in a text editor.

That is your basic view, however if you would like something more complex then use a spreadsheet application such as Excel. You can open log.txt up in a spreadsheet and it should display fine as we added in the comma’s to separate the data.

You can also use the AutoFilter which can be found in the Tools menu at the top of Excel so you can select one piece of data to filter in the logs such as one users session id or one browser to display all the data from.

Now you not only have great logs but they look shiny too.