Web development by PHP-Web-Host.com   Website Hosting by PHP-Web-Host.com
Web Hosting by PHP-Web-Host.com

SoftSmart Blogs!

SoftSmart Technical, Software and Web Related Blogs

Tel (Lon, UK): 020 8133 3460

 

 

Blogs

Using AJAX to load content dynamically without refreshing the page

May 6th, 2010

AJAX (wiki) is a great way of performing tasks which would usually require you to reload the web page. For instance, in an estate agent website I developed, logged in users could do a search for properties. If they found a property that they liked, they could click on the “Save to Favourites” link. This would redirect the page to another page which would save this property ID in the client’s favourites list, then redirect back to the search results page. When it reached the search results page now, this property obviously did not have a “Save to Favourites” link anymore…

Enter Ajax. By applying ajax to this page, I could have the user click the link, and save the property and remove the link without needing to reload the page. This saves bandwidth (no reloading pages), saves time (don’t have to run the search query again), and it just looks slick and professional.

Ajax basically works (in layman terms, read the wiki above for a more detailed explanation) by calling a web page from a javascript, and making the result of that page available to use in the script.

So, lets say I had a form on my page which asked the user to enter the name of a city. When they click on the submit button, it should look up the current temperature of that city and display it. Usually, we would submit the form and redirect between pages to display the result. Using ajax, the javascript can call a page that does the lookup, and it can then display the information on our page using the innerHTML property of the document….

Here is an example:

<html>
<head>

<script type=”text/javascript”>

xmlhttp = null;
count = 0;

var d = new Date();

function ClearFile(StartTimer)
{
xmlhttp = null;
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}

RndString = d.getFullYear() + “” + d.getMonth() + “” + d.getDate() + “”  + d.getHours() + “” + d.getMinutes() + “” + d.getSeconds() + “” + count++;

xmlhttp.open(“GET”,’http://localhost:81/test/DeleteFile.php?C=’ + RndString,false);
xmlhttp.send(null);

if(StartTimer == 1)
{
setTimeout(‘DoXMLPart()’, 2000);
}

}

function DoXMLPart()
{

InnerHTMLText = “”;

setTimeout(‘DoXMLPart()’, 5000);

xmlhttp = null;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}

RndString = d.getFullYear() + “” + d.getMonth() + “” + d.getDate() + “”  + d.getHours() + “” + d.getMinutes() + “” + d.getSeconds() + “” + count++;

xmlhttp.open(“GET”,’http://localhost:81/test/tags.txt?C=’ + RndString,false);
xmlhttp.send(null);

if(xmlhttp.responseText != “”)
{
InnerHTMLText = document.getElementById(“File”).innerHTML + xmlhttp.responseText;
document.getElementById(“File”).innerHTML = InnerHTMLText;

ClearFile(0);
}

}
</script>

</head>

<body onload=”ClearFile(1);” onunload=”ClearFile(0);”>

<div id=”File” name=”File”></div>

</body>
</html>

What this page does is the following:

When the page is loaded, the onload event in the body tag calls a function ClearFile(1). In clear file we set up our XMLHttpRequest  object and load a page called DeleteFile.php. Delete file simply opens a text file on our server called tags.txt and makes it blank.

It then sets a timer to 2 seconds (2000 milliseconds). When the time times out after 2 seconds, it will call a function called DoXMLPart().

The first thing we do in this function is set a timer to call this function again after 5 seconds. We do this because we want to continually check the server for data in this file. Obviously you could use ajax without  timers, for instance you could respond to the onclick event of a button.

Next, we set up our XMLHttpRequest object again and then call a page called tags.txt.

The property xmlhttp.responseText will contain any data from that call. In otherwords, it will contain the complete text of that file.

The line if(xmlhttp.responseText != “”) checks to see if there is anything in the file. If there is, we add it to the contents of the div called File. We then delete the contents of the file tags.txt

Using this method, we can add content to tags.txt and as we do it gets displayed to the user. Of course, we could call a php page as we did with DeleteFile.php.

A very important point is that IE 7 does not handle ajax terribly well. Internet explorer 7 (I haven’t tested the other versions)  uses some extreme caching. The  first time the ajax script is called it works fine, but thereafter it just keeps calling the ajax script that you called first. So, in our timed script above it would usually just repeat the first action over and over. It does not display new content, and even if the file is made blank, it keeps displaying what was in the file the first time. Its a real nuisance.

There is a work around though. We do two things.

1) You will notice that I have made the variable that holds the ajax xml request (xmlhttp = null;) a global variable.

2) By passing a unique query to the page you are querying, IE7 does not use the cached version.

That is the reason for this line of code:

RndString = d.getFullYear() + “” + d.getMonth() + “” + d.getDate() + “”  + d.getHours() + “” + d.getMinutes() + “” + d.getSeconds() + “” + count++;

We create a random  string which is made up of the current date and time, and an extra portion which is count. Count is a numeric value that starts at 0 and is incremented each time it is used. Note that it is not good enough to just use the count portion without the date and time portion. If the user presses refresh, the count starts at 0, but there are already cached versions of 0, 1, 2, etc, so the user will start to see actions which occured in the past repeating themselves… very confusing.

We then use this random string in our request:

xmlhttp.open(“GET”,’http://localhost:81/test/DeleteFile.php?C=’ + RndString,false);

This solves the problem with ajax (XMLHttpRequest) and IE7 perfectly. This problem does not occur in firefox.

If you have any comments or questions about this topic, please feel free to ask….

Click here to download the demo code

 


 

Bypassing DVD Region Encoding

April 26th, 2010

I have a growing DVD collection, and this consists mostly of series, or related movies, eg, I have most of “The Sopranos”, “Friends”, “Godfather” and other related mobster films.

So, because my DVD’s are mostly series or related, I prefer to burn the original disc to my laptop. That way I can watch it where ever, when ever.

Here is what I do:

1) I burn the DVD to an iso image on my hard drive using DVD Shrink. DVD Shrink is an open source package that rips DVD’s to iso images and supposedly shrinks them too. I say supposedly because the resultant file is still just under 5Gb. In any case, it does a brilliant job of this!

2) I use VideoLan to watch the iso image as if it were a DVD in the drive. VideoLan is maybe one of the best media players I have ever come across. Its simply brilliant. It is also free, open source. This will play movies and mp3′s equally well.

Ok, so that’s all simple enough, but I ran into a problem the other day. A while back I bought the BBC’s Planet Earth series, but I bought it from the USA, so the region encoding on my DVD player is different to the regional encoding on these discs. DVD Shrink was unable to read the disc because of the DVD Region Encoding. VideoLan on the other hand had no problem playing the disc, they seem to automatically bypass the DVD region encoding. This was pretty cool and I was really impressed once again with VLan, but not surprised.

The problem here is that I don’t want to carry my disc’s with me every where I go. Besides being bulky, they’re also expensive. I read about the regional encoding schemes and I was led to believe that there was probably not a great deal I could do. BUT, this did not deter me and I let logic prevail. Logic dictated that the encoding (or rather the result of the encoding) was not purely at the hardware level. There had to be a software level involved, because if it was purely a hardware issue, then not even Vlan would have worked.

After searching around for some time (and even trying to check the registry for the DVD Region Encoding), I came upon DVD Decrypter.  DVD Decrypter allowed me to bypass the region encoding of the DVD’s and rip them to my hard drive as an iso image.

Now, I am able to once again use VideoLAN to watch my DVD’s straight off my laptop.

Next, I will test what happens when I burn those iso images to DVD. Will it have the same encoding as the original disc, or will it be encoding free? Don’t know yet, but watch this space

 


 

Compiling a C++ dll with MinGW to use with Visual Basic

February 16th, 2010

Using a dll compiled with C++ in visual basic is really rather easy, its just a little hard to find good (EASY) information of how to do it. There is a fair amount of information for Microsoft’s C++ compilers, but what about us who write in a text editor and compile with g++ on MinGW? This post will show you how you can be using a c++ dll in visual basic.

I’m a big fan of ANSI C++, MinGW and the g++ compiler. I don’t like MS C++ compilers for various reasons. One of those is that I don’t believe it generates ANSI compliant code, and I certainly can’t compile for Linux from it.

If you are a visual basic (VB) coder, it may be necessary at times to use a dll compiled in C++. Or, you may be in a similar situation to myself: all of your projects are written in VB and you are porting everything over to C++. However, you have a problem. Porting everything at once will take a long time. If you port a module to C++, you would want to start using that module straight away with your existing VB projects (until you have ported the whole lot).

So, here is a quick guide on accomplishing that. This guide is very simple and is intended to get you started in the right direction.

Create a cpp file called “test.cpp”. In this file, paste the following code:

// Start of file

extern “C” // only required if using g++
{

__declspec (dllexport) int __stdcall FooBar (void)
{
return 343;
}

__declspec (dllexport) int __stdcall TimesTwo (int val)
{
return val * 2;
}

}

// end of file

Now we need to compile our dll. There are two steps (maybe they can be converted into a single step, but as I said, this is a beginners guide and I’m not an expert (yet) on the g++ compiler).

To compile, in MinGW, cd to the directory that has your cpp file and type:

g++ -c -Dtest_dll test.cpp

This will create a file called test.o

Now type

g++ -shared -o test.dll test.o -Wl,–add-stdcall-alias

This will create test.dll

Now, open a normal VB  project and in the form’s code space, paste the following

Option Explicit

Private Declare Function FooBar Lib “C:\msys\1.0\home\John\Dll_with_VB_test\test.dll” () As Integer
Private Declare Function TimesTwo Lib “C:\msys\1.0\home\John\Dll_with_VB_test\test.dll” (ByVal val As Integer) As Integer

Private Sub Form_Load()

Debug.Print FooBar

Debug.Print TimesTwo(5)

End Sub

Take note of two things here:

1) The path to the dll must obviously be changed to be correct on your system

2) In the second declare, we pass an integer called val in to the dll. If you leave out the ByVal, the value is corrupted, so the ByVal bit is important.

That’s it, please post back here if you have any useful insights. Lets learn (and port our software) together!

 


 

Using Alt Tags in Images

February 2nd, 2010

This is a quick note about alt tags.

Please see this article for more info: Can google see your website?

The reason I’m writing this again is because of its importance, but more importantly because of how many people do not do this.

Imagine you’re sitting in a movie theather, 60 / 70 years ago. Movies have not yet advanced to a stage where there is sound, so its a silent movie. Not very nice hey? And to make matters worse, you’ve brought your blind friend with you.

So, what has this got to do with the search engines. Well, you need to think of your website as an old fashioned movie with no sound. And you need to think of Google as your blind friend. He can’t see anything, and, as there is no sound in the movie, he can’t hear anything. Besides the pop corn, its really a waste. He needs to read braille.

Images on your website are like that silent movie. Google, being blind, needs the braille of the web, that is, it needs plain text! If you have a website with loads of images that look really great to visitors, remember, your blind friend google can’t read them (or the other search engines).

So, what should you do? Provide Alt text in images.

Here is an INCORRECT image tag <img src=”someimage.jpg”>.

Here is a CORRECT image tag <img src=”someimage.jpg” alt=”Yay, google can read this!”>

Ok, so, a demonstration is in order. Now, lets see an example, then you can rush off and try this on your own site. We are going to work with three php files:

1) image_noalt.php which has only an image as the main body. This image has NO alt text. So, this page is very bad and google can’t index it correctly. What about the meta keywords tags? Look here, google DOES NOT USE THEM, or look here! Matt Cutts is a chief engineer from Google. If I have his title incorrect, please forgive me, I don’t work there, I don’t know who gets called what, I just know that he’s a pretty important person there!

2) image_alt.php. This page has the same image, but it DOES have alt text, so google can “read” what your image is about, and can thus index it.

3) split.php. Here we have split this image. We have kept the heading as an image because we wanted the cool shadow effect (which you can probably do with some clever CSS anyway). The header image has alt text. Then, for the two smaller images, we’ve made their titles plain text, so google can index that. We’ve also added alt text to both the smaller images, so google has 5 pieces of information here.

To see what google more or less sees with these files, we’ll do a little comparison.

Below we have three examples. One is a page with NO ALT tags, and the entire page is just an image. There is a clickable link so you can see what the page looks like visually. Next to the clickable link, after the | symbol, is a link you need to copy and paste into a web browser. This will show you how google sees the page.  Do that for each of the three examples below. Note that when you copy the second link to see how google sees your page, you will notice some banners at the top. Those are advertising banners put there by that company. We are just looking at the text parts which is what google sees.

1) Normal image_noalt.php | http://www.delorie.com/web/lynxview.cgi?url=http://www.softsmart.co.za/blog/image_noalt.php

  • Note here that the image name big_image.jpg is all that is visible to google, in terms of the main body text, not good at all

2) Normal image_alt.php | http://www.delorie.com/web/lynxview.cgi?url=http://www.softsmart.co.za/blog/image_alt.php

  • Here there is alt text that is visible to google, so it is an improvement

3) Normal split.php | http://www.delorie.com/web/lynxview.cgi?url=http://www.softsmart.co.za/blog/split.php

  • Here there is alt text ON EACH images, as well as plain text that is visible to google, this is the best way of making sure that google know’s what your site is about.

Conclusion

If you use image, use alt text. Always! No exceptions! If you are able to split the image up, then do that. Use plain text where possible.

 


 

24 Questions to Ask Your Web Hosting Company

January 21st, 2010

Any business these days requires a website. It has become an expectation. Herewith, a list of 24 questions that you should ask your web hosting company before you purchase web hosting.

Technical Support:

Technical support must be available to you.

1. What do they provide?
- SoftSmart.co.za provides live chat (link available through all pages of our site).
- We provide telephone support (numbers on our contact page).
- We provide email support which is tracked via a support ticketing system.
- Knowledge base with FAQs.

2. When are they available?
- Telephone and live chats are available from 8H00 till 17H30, Monday to Friday, and usually beyond that.

3. Does tech support cost extra?
- There is no fee for tech support

Storage:

Ensure that you have enough space to expand in the future.

4. How much storage do they offer? (A typical Web site uses between 20-30 MB)
- LOADS. Our smallest package is 500Mb of disk space

5. Do they offer enough extra space for your business to grow into? 100MB is a good starting point.
- Sure. Our largest package has 10Gb disk space. If you need it, please email us to find out about dedicated hosting.

Domains:

Getting a Domain name for your business is one of the most important things you could do.

6. Will they register your Domain name on your behalf?
- Yes, when you order your hosting package, you enter the domain name of your choice.

7. How long will it take?
- Average time is < 2 hours.

8. Is there any extra cost to you?
- Most packages include a free domain name for the first year. Thereafter domain names cost R100 (+- $15) per year.

Design:

There are 3 basic website design options. 1) Hire a web developer to design the entire website. 2) A template solution that is inexpensive, but designs are not unique.

9. Do they have a builder that you can manage easily?
- Yes, we have Site builder (link to demo here).
- We have thousands of FREE web templates within our CPanel area.
- We have a great online tutorial for web authoring (link here).

10. What type of computer background do you need to design your site?

- Dependant on what option you prefer above.

11. Do you have control over content and updates?
- Yes, your site is loaded via FTP, so you control every step.

Email:

12. How many email aliases comes with your package?
- This differs with the packages, from 5 to unlimited.

13. Will your emails have the domain name in them for a more professional appearance (eg, joe@mydomain.com)?
- Is there any other way???

14. What is the cost to add extra emails?
- You can easily add up to your package maximum in CPanel at no cost

15. Are there any additional costs?
- No!

Cost:

Make sure there are no hidden costs.

16. What are the initial setup fees and what do you get exactly?
- We charge no setup fees.

17. Are there any additional charges?
- Not really… If you go over your data allowance (which is huge, 5Gb on the smallest package) for 3 consecutive months, we will require you to upgrade your account.

Contract:

18. Am I locked into a contract?
- No, you pay per month.

19. May I cancel at anytime?
- Yes you can! (to paraphrase president Obama).

20. Are there any penalty fees for switching or closing my account?
- Only that you loose out on great service.

21. What happens to my content?
- Your content is yours. You can simply get it all via FTP (or as a backup from CPanel) before cancelling. Your      domain will also be transferred (note that some registrars charge about $10 to transfer domains, so you may need to pay that to them directly).

Value:

22. What makes them better than their competition?
- We provide great support. We use our own servers for our own websites and we have all the value added services, like web development, custom software development, graphic designers, etc. Because we are software / web developers we can answer technical question which extend beyond just hosting support

23. What exactly sets them apart?

- We believe the old adage that the “customer is king”, give us a try. Mail us and ask about your first 3 months ABSOLUTELY FREE!!!

24. Does the web host provide the features that you need for your web site?
- We have many free scripts like ecommerce applications, WordPress, etc for free and easy to setup in CPanel.

 


 

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

 

 

We accept PayPal

 

Web Hosting by PHP-Web-Host.com Website Hosting by PHP-Web-Host.com

[ Home ] | [ Software ] | [ Web Development ] | [ Resources ] | [ Contact ] | [ Privacy Policy ] | [ Acceptable Use Policy ] | [ Terms of Service ] | [ Sitemap ] | [ Clients ] | [ Affiliates ]

[ PHP Web Hosting ] | [ Linux Web Hosting ] | [ 500mb PHP Web Hosting ] | [ 1Gb PHP Web Hosting ] | [ 3Gb PHP Web Hosting ] | [ 6Gb PHP Web Hosting ] | [ 10Gb PHP Web Hosting ]

[ HTML Tutor ] | [ CSS Tutorial ] |