This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.

Tuesday, January 31, 2012

Redirecting the Browser to a Mobile Web Page

imageIn this day in age, most web visitors are now coming from cell phones or mobile devices.  You need to have a version of your website that is designed for mobile devices.  One of the major issues with this is having the ability to detect if the browser is a mobile device.  There are hundreds of different browsers out on mobile devices right now, so I found the following website to help with this:

http://detectmobilebrowsers.com/

This site has the open source code you can use to add to your main webpage.  If the webpage detects it is a mobile device, it will automatically redirect to the mobile version of the page.

The following is the .PHP example of this:

Resizing the Web Page to Fit the Cell Phone Screen

imageOne of the issues we ran into when we started creating webpages for mobile devices was to have the screen auto-zoom so that the visitor did not have to take the extra step to zoom in on the content.

After several searches on the Internet, I came across the following code that you add as a meta tag to solve the problem.  We actually tested this on 4 different mobile browsers and it seemed to work just fine.

<meta name="viewport" content="width=device-width; initial-scale=1.0">

What this code does is resize the screen to the scale of the cell phone (or mobile device) browser.


That’s it.

Saturday, January 28, 2012

Reading a Textarea Field Into Separate Lines

imageOn occasion, you may run into the need to create a small utility the will read each line of a textarea field and process each line separately.  I have done this on a few occasions (like the domain upload for YourPopLinks.com or the Quick Task function on DNSTCcontact.com). 

Here is the code:

1.  You setup a field in your form that is a textarea, let’s call it dataList.

2. On the processing side, you would use the following code:


$dataList = trim($_POST['dataList']);
$dataProcess = explode("\n", $dataList);

foreach ($dataProcess as $line) {

$cleanData = trim($line);

...
process $cleanData
...

}


 


The first trim will remove the carriage return bit at the end of the data, the second trim within the foreach loop, will remove the carriage return at the end of each line.  I have seen examples of this where it used the second trim above, but it does not leave the ability to split the data into the $dataProcess array.


That is pretty much how you do that.  Works pretty good.

Thursday, January 26, 2012

Garbage Characters Being Displayed from Blog Posts

imageThe following describes an issue that we had with pulling RSS feeds from WordPress and displaying them on web pages and how we resolved the problem.  The main issue was that some characters where being displayed as garbage on the screen.  It took many months of research and testing out different things to get this issue resolved.

 

Problem

The main issue lied within the character encoding of the page where there information was being displayed.  The information coming from WordPress and the RSS feed was encoded with UTF-8 which allows for more than 128 ASCII characters; whereas, the HTML page it was being display on was encoded with iso-8859-1.

Solution

Change the encoding on the HTML page to UTF-8.  This fixes the issue and clears up all of the garbage characters.

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Additional Resources


http://en.wikipedia.org/wiki/UTF-8


http://phpplanet.org/stop-junk-characters-%E2%80%98aetm%E2%80%99-from-appearing-instead-of-an-apostrophe/

Sunday, January 22, 2012

Server Cut Over Update

imageAfter several days (15 days) of moving over accounts, checking for errors, fixing issues, changing password, and so on, we are down to 4 more domains left to complete the move to the new server.  So far, everything has been working out great and the new server is working better than expected.   If you have not heard from DNSTC directly, then you site is probably already on the new server. 

You can check by sending a ping request to your domain and it should be pointing to 74.219.116.125 instead of 74.219.116.123.

This has not been a stress free project, but one that needed done desperately.  In the past 10 days, the old server has locked up about 20 times and it is slowly dying.

We got a great 7 years out of that server and billions of packets of traffic.  It will be sadly missed; however, it will under go some slight surgery and will reappear as a gaming server in a week or so after everything has been moved over.  I will post another update once everything is moved.

Server Cut Over Update

After several days (15 days) of moving over accounts, checking for errors, fixing issues, changing password, and so on, we are down to 4 more domains left to complete the move to the new server.  So far, everything has been working out great and the new server is working better than expected.   If you have not heard from DNSTC directly, then you site is probably already on the new server. 

You can check by sending a ping request to your domain and it should be pointing to 74.219.116.125 instead of 74.219.116.123.

This has not been a stress free project, but one that needed done desperately.  In the past 10 days, the old server has locked up about 20 times and it is slowly dying.

We got a great 7 years out of that server and billions of packets of traffic.  It will be sadly missed; however, it will under go some slight surgery and will reappear as a gaming server in a week or so after everything has been moved over.  I will post another update once everything is moved.

Tuesday, January 10, 2012

Server Migration Under Way

imageWe are currently in the process of migrating over to the new server for website and e-mail hosting.  So far the project has been going along fantastically.  We need to get all sites moved as soon as possible do to a temporary hosting license.  If DNSTC does not maintain your domain registration, we will be in contact with you for the new server's settings.

Server Migration Under Way

We are currently in the process of migrating over to the new server for website and e-mail hosting.  So far the project has been going along fantastically.  We need to get all sites moved as soon as possible do to a temporary hosting license.  If DNSTC does not maintain your domain registration, we will be in contact with you for the new server's settings.

Monday, January 2, 2012

Formatting MySQL datetime field in PHP

If you would like to get a nice format on the datetime field stored in MySQL, use the following code:

<?php

    $datetime = strtotime($row_links['dateAdded']); // The date time field
    $formatDate = date("m/d/y g:i A", $datetime);
    echo $formatDate;

?>

This will output something like:

01/01/12 8:07 PM

If you want more formatting options for the date(), you can review the manual on PHP.net here.

Form Validation with JS

imageOne of the important elements in form design is the implementation of form validation.  This helps to ensure that the data being submitted is cleaned and that the user enters the required information that you want for the form.  If you do not include any type of validation on your form, then it is possible to get corrupt data or open your form for possible hacking attempts.

To create a great form validation system, there are four steps to implementation:

  1. Make sure each of your fields have an id attribute.
  2. Include the validation functions within the heading of your page.
  3. Create a unique validation function for your form.
  4. Add the validation code to the onSubmit attribute of the form.

Validation Functions

We have created several functions that can be used to help with the validation of a form.  These functions will check to see if the field is empty, check to see if the field is numeric, check to see if the field is alpha numeric, check the length of the field, check to see if an item has been selected, and check to see if a valid e-mail address has been entered.

Add the following functions within a javascript section within the heading:

function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}

function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function isAlphanumeric(elem, helperMsg){
var alphaExp = /^[0-9a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function lengthRestriction(elem, min, max){
var uInput = elem.value;
if(uInput.length >= min && uInput.length <= max){
return true;
}else{
alert("Please enter between " +min+ " and " +max+ " characters");
elem.focus();
return false;
}
}

function madeSelection(elem, helperMsg){
if(elem.value == "Please Select"){
alert(helperMsg);
elem.focus();
return false;
}else{
return true;
}
}

function emailValidator(elem, helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

Unique Validation Function for the Form


You will not have to look at each of the fields that you want to validate, and create a function that is called when the form is submitted.  The following is an example of how this will work.

function validateForm() {

var valid = false;

var subcat = document.getElementById('subcat');
var name = document.getElementById('Name');
var email = document.getElementById('email');
var linkText = document.getElementById('linkText');
var linkURL = document getElementById('linkURL');
var siteDescription = document.getElementById('siteDescription');
var reciprocalPage = document.getElementById('reciprocalPage');

if(notEmpty(subcat, "You need to select a category.")){
if(notEmpty(name, "You need to provide your name.")){
if(emailValidator(email, "You need to provide your e-mail.")){
if(notEmpty(linkText, "You need to provide a title for your link.")){
if(notEmpty(linkURL, "You need to provide a URL for your link.")){
if(notEmpty(siteDescription, "You need to provide a description for your site.")){
if(notEmpty(reciprocalPage, "You need to provide the URL to the page you placed our link.")){
valid=true;
}
}
}
}
}
}
}

return valid;

}

Explanation:


Here is the flow as to how this function works…



  1. The variable valid is set to false.
  2. The value of the fields you want to validate are assigned to variables.
  3. The nested condition statement goes through each variable and validates the fields calling the appropriate functions.
  4. The function then returns the valid status back to the form.  If the status is true, it is submitted.  If the status is false, then a window pops up and tells the user what they need to correct in order to submit the form.

Adding the validation function to your form


The last thing you have to do is add the validation call to a “OnSubmit” attribute of your form.

<form action="post.php" 
name="myform"
method="post"
onsubmit="return validateForm();">

Now when the submit button is clicked, the validation system should check the fields you want validated.