
05 Jun, 2009
Posted by: john In: javascript| php| programing
Earlier this week I had an interesting problem. I needed to have some javascript code run from within the page being called via AJAX. The javascript relied on the values being set in the page being called so it could not be setup on the page before hand. It had to be called afterward.
It basically came down to having to eval() the XMLHttpRequest data being sent. But thanks to developersnippets.com they wrote a very helpful article that fixes the issues I was having.
Below is an explanation of the files included in the demo. We first need to make a generic page that has a single link that when clicked loads a separate page through an AJAX request.
// index.phpsome content that is here when the page loads change div
Next we need to create the page that will be loaded via the AJAX request. Now the key here is that the page being loaded has Javascript that needs to be ran. So for our example we will launch a simple alert() commend that will show us a message along with a passed $_GET variable.
// load_page.php Page has been succesfully changed [] change div
And that’s it for the very basic example of how you can use this. (not practical but should give you the concept) Please leave a comment below if you have any questions or need any help with this.
My brother bought us practice round tickets this year to the Masters golf tournament in Augusta GA. Only living 30 minutes away, it’s surprising this was my first time going. Any how the day was good, we’d seen the course and were about to head home when we notice a large group around the putting green so we walk over to check out what was going on.

Tiger Woods is what was going on! Very cool – got to see him in person only about 5 feet in front of where we were standing.
02 Mar, 2009
Posted by: john In: javascript| programing
This one about drove me crazy all night trying to think of why this does not work and to be honest I still don’t understand why it doesn’t. But below is a solution to the problem.
The problem was I was trying to close a popup and force the parent page to load a URL using onload.
So within the popup, I saved the form changes to the database and if everything was saved fine it would return to the popup with the code below.
< body onload="window.opener.location = '/directory/?action=confirmation'; window.close();">
But for some reason this would cause IE7 (didn’t check any version below 7 and worked fine in Firefox & Chrome) to just load and load and load but never actually load the page it was sent to. The big blue “e” would just spin. The URL was correct and it wasn’t stuck in some endless loop. But like I said, I’m still not sure what caused it to do that, but below is the solution that seemed to have worked.
Rather than placing the close and redirect in the onload, I simply added them within a script tag and placed it above all the other scripts.
My only guess is that by putting the code in the onload was causing it to not fully run the redirect. Any ways, I hope this helps someone else out there.
Please let me know if you know the reason what caused this error.
For work we needed a way to allow the customer to preview what their Bible imprint text would look like before they placed their order. I’m sure there are ways to do this with JavaScript, but we chose to do this with PHP to prevent the site from relying on Javascript (there was already enough on the page).
View Demo
Download files (32 KB)
function text2image($text,$text_type)
{
$text = ereg_replace("[^A-Za-z0-9 -]", "", $text); // change to allow whatever characters you made images for
$length = strlen($text); // finds number of characters
for($b=0; $b<$length; $b++) // loops through each character to convert to image
{
$text_type_function = $text_type; // resets font type each time
if($text_type_function == 'sc') // script font type
{
if(ctype_upper($text[$b])){$text_type_function = 'sc_u';} // changes text type to upper
elseif(is_numeric($text[$b])){$text_type_function = 'sc';} // checks for number (not really used in this function yet)
if($text[$b] == ' '){$word .= ' ';} // could change to be blank image, but text spaces seem easier
else
{
$image_word .= '
';
}
}
else // else block type
{
if(ctype_upper($text[$b])){$text_type_function = 'bm_u';}
elseif(is_numeric($text[$b])){$text_type_function = 'bm';}
$text[$b] = strtolower($text[$b]);
if($text[$b] == ' '){$word .= ' ';}
else
{
$image_word .= '
';
}
}
}
return $image_word;
}
// useage
$text = 'Preview this font please';
echo text2image($text,'sc');
The above function works for the two fonts included in the zip file, but to add more, just create an image of all the letters and add another elseif statement to the function.
If you have any questions or need any help with adding more fonts, please either use the contact form or leave a comment below.
One morning, the husband returns the boat to their lakeside cottage after several hours of fishing and decides to take a nap. Although not familiar with the lake, the wife decides to take the boat out. She motors out a short distance, anchors, puts her feet up, and begins to read her book.
Read the rest of this entry »
27 Jan, 2009
Posted by: john In: linux| programing| web

The other day we ran into a good problem that our site has grown and we are in need of a new server. So we ordered the server and now we need to transfer all the files from the old server to the new one. But rather than downloading all the files to our local machines then re-cuploading them to the new server, we’re going to show you how you can skip the middle man and transfer files from server to server.
The only requirements is that you need to have SSH access to both servers.
We’re going to be using the Linux command scp which stands for secure copy. (see http://linux.about.com/od/commands/l/blcmdl1_scp.htm for a complete listing of all the available options for scp)
We’re going to be using the following options:
// To transfer all the files in the httpdocs directory to a folder on the remote machine scp -rpC /var/www/httpdocs/* remote_user@remote_domain.com:/var/www/httpdocs // Transfer only PHP files scp -rpC /var/www/httpdocs/*.php remote_user@remote_domain.com:/var/www/httpdocs
Also, if you’re going to transfer a lot of data between the webservers, you probably want to add the nohup command too. nohup runs a command even if the session is disconnected or the user logs out. Another bit you can add is trailing ampersand (&) to the end the command to launch it in the background and get your command prompt back right away.
nohup scp -rpC /var/www/httpdocs/* remote_user@remote_domain.com:/var/www/httpdocs &
Hope this helps someone as much as it did me today.
This great tip came from Wes Widner of werxltd.com.