December 14th, 2008
GOOPTracker is an ad click tracker for publishers who have ads on their site(s). This is an alternative solution to other ad click scripts such as ClickAider and AsRep to name a few.
So what makes this one different from the others?
To start, its free. The code isn’t encrypted or hard to look through… you can easily understand what is going on through the lines of the code and I have made comments throughout it as well. You don’t need to sign up, or pay; you just download the files, configure/modify it ever so slightly to fit your needs (if you want), that is all. The script is MIT License, but I appreciate any enhancements or updates you have done to the code to help not me but everyone.
Read the rest of this entry »
Posted in GOOPTracker > Javascript > PHP | No Comments »
August 11th, 2008
Recently, I have been working on a project that involved uploading multiple files to the server with PHP. There are several ways to go about doing this: 1) Upload each image one at a time (but that really isn’t a multi uploading way) or 2) Place all the images in an array. Option 1 is pretty much ruled out because you aren’t uploading multiple images at once; And Option 2 is the way to go because that is the purpose of this tutorial, but there is a small problem that you might not be aware: over exceeding the posted max file size that is set in your php.ini file. Assuming you don’t have your own server, and depending on your host, you might be able to ask them to bump this up to a more reasonable amount other than the default 2MB. But usually you are limited because you most likely have a shared web host and they don’t want you to upload too large of a file to disturb the other users on that server, or they don’t want you to take too much space. Which is understandable.
So my solution was to upload each image at a time without leaving the page. How is this possible? With iFrames. I did a simple add and remove row with Javascript, allowing the user to select how many and what files to upload. Once the user selected all the desired files, I use Javascript again to check if all the files had the correct extension (.png in this case), then submit each form at a time after the other one got completed. I am not going to bother to explain the code the this time around, because I believe the explanation is well enough the code to understand.
Here is the sample
(of course the files aren’t being uploaded… just the page refreshes letting you know if it worked correctly or not).
And here are the files used to do the magic: zip
Posted in Javascript > PHP | No Comments »
July 24th, 2008
When dealing with forms its very important to validate what the user entered so you don't get false email address, phone number, zip code, etc. There are multiple ways to validate what the user entered in the input field of your form(s). The way I suggest and I am going to share with you is through Javascript. I wrote a nifty little function called validate which takes the two required parameters, the first being what you want validate, and the second is the value or string to validate/test it with. Here is the function:
JavaScript:
-
function validate(what,str) {
-
if(what == "email") {
-
// sample@sample.com
-
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
-
return filter.test(str);
-
} else if(what == "phone") {
-
// (123) 456-7890
-
var filter = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
-
return filter.test(str);
-
} else if(what == "num") {
-
// must be a number, or can't be zero
-
if((str / str) == 1 && str != 0) { return true; }
-
else { return false; }
-
} else if(what == "zip") {
-
// 12345 or 12345-1234
-
var filter = /\d{5}(-\d{4})?/;
-
return filter.test(str);
-
} else if(what == "date") {
-
// MM/DD/YYYY
-
var filter = /^([1-9]|0[1-9]|1[012])\D([1-9]|0[1-9]|[12][0-9]|3[01])\D(19[0-9][0-9]|20[0-9][0-9])$/;
-
return filter.test(str);
-
} else if(what == "url") {
-
// http://www.sample.com or www.sample.com
-
var filter = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
-
return filter.test(str);
-
} else if(what == "ext") {
-
// personally, I only accept images with jpg/jpeg, gif, or png format. But this can anything to your liking
-
str = str.toLowerCase();
-
if(str.lastIndexOf(".jpg") == -1 && str.lastIndexOf(".jpeg") == -1 && str.lastIndexOf(".gif") == -1 && str.lastIndexOf(".png") == -1) { return false; }
-
else { return true; }
-
}
-
}
This function does a lot different validating and testing, and of course this can continue to grow to your pleasing. As of now, the function is set up to return either true or false. I suggest keeping it this way if you plan adding or changing some of the regular expression checking. This is how to use the function:
JavaScript:
-
// get the phone value from the form
-
var phone = document.forms[0].phone.value;
-
-
// validate the phone number
-
if(!validate("phone",phone)) {
-
alert("Invalid Phone Number entered");
-
return;
-
}
If the phone number is invalid, then it will do an alert telling the user that they didn't enter the correct syntax for the phone number. If it was entered correctly then it was entered correctly and javascript will continue with the rest of the script.
I hope you find this useful. Enjoy!
Posted in Javascript > Website | No Comments »
May 31st, 2008
DomReady has been starting to become all the craze lately with the language Javascript to use for HTML pages. But what is it? DomReady allows you manipulate with all the elements on the HTML page before the entire page loads. What use can this be if you can just use window.onload instead? Well, imagine a large site like MySpace.com, or IGN.com, which have a lot of flashy banner ads and images to load. My guess for the entire page to load can take ~10 seconds, assuming we are on a fast connection speed to the Internet, respectively. That isn't bad, most of us can wait 10 seconds for a page to load if it's our favorite site to visit. But for some users who don't have a high speed Internet, they will have to wait a lot longer for the page to load, and therefore the Javascript window.onload function won't be executed until it takes it sweet time to load.
Read the rest of this entry »
Posted in Javascript > Website | No Comments »