Author Archives: Orville Chomer

Experiments with Getting Web Content Using ColdFusion and PHP

Share this:  

So you want to get content from another web site out there to use on your site. You may be doing screen scraping of a page out there… But a better use is to get info from some sort of a web API.

Case in point: Calling a URI from the U.S. Weather Service to get current weather information.

… This URI will return weather data from Chicago’s Midway Airport

Using ColdFusion

Here is a ColdFusion file for getting info on the current weather in Chicago:

It works fine. I do any Ajax call to “weather.cfm” from my home page, parse of the current temperature, and weather description and display it on my home page.  Nice!


If I call “weather.cfm” directly, I get weather data back for Chicago’s weather:

Below you can roughly see how it displays this page in Safari:

If you were to view the source, this is approximately what you would see, XML output:

Again, I have a JavaScript routine that calls weather.cfm via AJAX and pulls data from the <weather></weather> and the <temp_f></temp_f> tags.

This was running in ColdFusion Developer on my iMac and I can access on my personal wifi network.


Using PHP

I also wanted to do the same sort of thing using PHP. I decided I would use cUrl. Here is the code I used in a file called “weather.php”:

Notice that the URL is the same one as I’m using in the ColdFusion example.


So what happens if I directly call this “weather.php” page I created in my Safari web browser?

Well, we get a page like the one displayed above. Bummer! This is running on a PHP MAMP server on the same iMac as the ColdFusion server is. And trust me, the ColdFusion server is not calling this URL with any special permissions!

This led me to suspect that there was something different about the HTTP Header being sent by the ColdFusion server than was being sent by the PHP server using cURL.

But how to figure out what ColdFusion is doing differently than PHP?  Create a new PHP page to call instead of calling the xml file…



HTTP Header Test Page

I was going to create a PHP page that would look at it’s HTTP Header values and output them to the page for me to be able to see!

Here it is:


Now, if we changed weather.php to point to this URL, what do we get?

Note that the ‘1’ at the bottom is an artifact of cUrl (unless you set the CURLOPT_RETURNTRANSFER option to true.

What about doing the same thing with weather.cfm ?

There is definitely a difference between the two. Both have the same value for “Host”. Not much else is the same! It could be that the PHP request has HTTP Headers that the server does not like… But I’m going with the assumption that the PHP request is MISSING one or more HTTP headers that the web server ( is expecting. So lets modify our weather.php file:


Notice above how I added a new block of code (lines 8 through 12). This is adding three headers to our HTTP Header: ‘User-Agent’, ‘Connection’, and ‘Accept-Encoding’. I saved my changes and refreshed this page.


But is the server looking for all three of these headers?

I remove ‘Accept-Encoding’.  I refresh the browser.  It still works.

I remove ‘Connection’.  I refresh the browser.  It still works.

And (of course) I remove ‘User-Agent’.  I refresh the browser.  And of course it fails.

So, ‘User-Agent’ is the key. Currently, in our example, it is set to the value of ‘ColdFusion’. Because that is the value I got when running the ColdFusion page. But actually (of course) our page is a PHP page when is requesting the info.

I change the value of ‘User-Agent’ from ‘ColdFusion’ to ‘PHP’. I refresh the browser and it works.

I wonder, is:   looking for specific values for this header, or just that the ‘User-Agent’ header is present in the HTTP header?

So, I change the value of ‘User-Agent’ to: ‘SugarBoogers’.  I refresh the page and it works! This means that the server (at least in this case) is just checking to make sure that the ‘User-Agent’ HTTP Header is present and has a value… but doesn’t care WHAT the value is (I’m sure that ‘SugarBoogers’ is not a common user agent to check for!

Wrapping It Up

You might be able to “screen scrape” a web page without custom setting any HTTP headers. But I suspect that if your calling some sort of XML feed, JSON resource, or web service URI, there’s a good chance that you will need to set the ‘User-Agent’ HTTP header in order to get it to work.

Any comments? Thoughts? Let me know.

Happy Coding!



Entity Render Experiment in CodePen

Share this:  

Here is a little something that I’ve been messing around with in @CodePen. It renders the block diagram of a “data model.”  If you’ve ever used a modeling tool like Erwin this will look familiar…

Screen Shot of Model Render Demo

This is an experiment in rendering a lot of UI elements (entities) without having poor performance. In that, it will only render to the DOM entities that can currently be seen in the view port.

Right now, by default, it generates 200 entities. Try 2000 or 20000, or any other positive integer value, and see how it performs!

There are still a few bugs in it (its rendering too many entities at a time for example), but I think it proves its certainly possible.

You can try it yourself on CodePen here:

Let me know what you think.

I’ve Installed Node.js

Share this:  

I’ve installed Node.js on my Mac. I want to mess around with Node.js later. But what I am interested in right now is NPM.

NPM (Node Package Manager), as it turns out, is being used as a module installer tool by all sorts of other tools and seems to have become a “thing.” It is a command line tool.

Installation: If you want to install it, you need to install Node.js which includes NPM as part of its installation. So, I have installed it.

I am going through a course on called:  Learning NPM the Node Package Manager. Ray Villalobos is the instructor.


Web Page Resize Event Experiments

Share this:  

I’ve got some specific JavaScript-based widgets that I want to develop. And I thought I’d share some of my design experiments with you.

This article delves into the idea of capturing the resize event of a DOM element to help create a better custom web page control using JavaScript and CSS. Then it discusses how these controls work, gives a few examples of commercially available controls, and then finally gives a suggested way to handle things when a custom control (that you have designed) is resized on your web page!

Read more

Time-Out ,3D Printing Stuff, Web Stuff and More

Share this:  

I’ve been off of work since just before Thanksgiving and for the month December. After a really hard year of work I finally have time off. It is wonderfully strange!

  • Extruder on my Makerbot 2 3D printer got totally messed up (I may do a post on this going into more detail later).
  • Started watching more videos on on modeling in Sketchup. Also on YouTube.
  • My 3D Printer was out of commission for awhile.
  • I joined the 3D Printing Group over on Facebook. You have to submit a request for membership in order to join since it is a closed group.
    • This is an awesome group!
    • There are a lot of members here who know a lot and are passionate about 3D Printing!
  • I subscribed to the 3D Printing Nerd YouTube channel run by Joel Telling.
    • One thing I saw on his channel was his review of the pre-release version of Lulzbot TAZ 6 3D Printer. I was intrigued. I could buy it on Amazon if I wanted to.  $2,500.00  … a Lot of money… hmmm…
  • I started learning more about how to code a PhP web site. I set up several different internal sites to do useful stuff for me and my family.
  • I started looking into writing my own blogging software again. We’ll see where THAT goes!
  • Saw on the 3D Printing Group a contest to design a printable Nerf dart gun. Got in on the contest rather late… I did submit an entry… basically all I had time to do was an air piston that shoots a single Nerf dart out of it’s barrel that is powered by two rubber bands.
  • Also saw on the 3D Printing Group someone asked about what anyone thought about the Lulzbot TAZ 6 3D Printer.
    • There was a bunch of responses of users who had the printer, loved it, loved the service, and were showing pictures of things that they printed on their new printer.
    • This pushed me over the edge. My Makerbot still was not working at that time, and I just did it!
  • I really like my new TAZ 6 printer!  I like that it auto-levels!  I like how many different kinds of filament I can use with it.  More on the TAZ in another post.
  • I bought some parts to fix my Makerbot from Fargo 3D Printing.
  • Eventually I fixed my Makerbot and got it working again. Yay!
  • Upgraded my version of WordPress here to the latest version today (its about time)!

Enabling F12 Developer Tools in IE

Share this:  

For some strange reason on my work computer the F12 Developer Tools option was disabled on my Tools menu in Internet Explorer (IE 11). Other devs on my team had access to it, but I did not.

Well, I found out, at least in my case, that if I did the following steps, I could enable this option:

  • Click the “Start” button in the lower left-hand side of your screen.
  • Select the Run… option.
  • Type in the following and hit the Enter key:      gpedit.msc
  • You may be prompted to enter your Window user name and password, if so, enter it in.
  • The Local Group Policy Editor will come up.
  • On the left hand side of this window is a tree navigation control.
  • Make sure that the Computer Configuration node is expanded.
  • Under that, expand the Administrative Templates node.
  • Under that, expand the Windows Components node.
  • Under that, expand the Internet Explorer node.
  • Under that, select the Toolbars node.
  • Select the setting:  Turn off Developer Tools
  • Click the edit policy setting link to the left.
  • Pick the Disabled option and Apply the changes.

That is it! After I did this the F12 Developer Tools option in IE was accessible to me!

Doing a Page Redirect from a Java Struts2 Action Class

Share this:  


I began working on a web site written in Java using Struts2. I wrote a general purpose class to be used by the application. One method in the class was supposed to check if the user was logged in. If not, redirect to the logon page (I did NOT want to add a tag entry to every <action> block in the struts.xml file)!

I searched the web and did not find anything that worked quite right. Finally, after some experimentation, I got something working! Here is some sample code for you:

Helper Class

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.*;
import javax.servlet.http.*;

public class myExample {
   public void doARedirectToGoogle() {
      HttpServletResponse response = ServletActionContext.getResponse();
      try {
      } catch (IOException e) {
      } // end of try / catch
   } // end of doARedirectToGoogle() method
} // end of myExample class

Note the try/catch block must be in place in order for this to compile and work.

Struts2 Action Class:

import com.chomer.demo;

public class demoPage extends ActionSupport {
   public String execute() {
      myExample demo = new myExample();
      return "success";
   } // end off execute() method
} // end of demoPage class

Action Block added to struts.xml:

<action name="demoPage" method="execute" class="com.chomer.actions.demoPage">
   <result name="success">/pages/demoPage.jsp</result>
   <result name="error">/pages/demoPageErr.jsp</result>

Success Page… demoPage.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
      <h1>This page will come up if the redirect does not work!</h1>

Failure Page… demoPageErr.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
      <h1>This page will come up if the redirect does not work AND there was an error!</h1>

In the above example I made up some arbitrary packages names. You will have your own structure in place. If this works you should never see the success or failure page.

In a real world scenario, the redirect would happen only if a certain condition was being met (such as the user is not logged in). If the user were logged in, demoPage.jsp’s contents would appear.

“I Lost My Underwear” App Version 2 Has Been Released to Apple App Store

Share this:  

So far, the only app I have ever finished and placed in the App Store is not my own app. It is an app I have written for a friend. He wrote a book of humorous poems with illustrations called “I Lost My Underwear Today and other flights of imagination.” You can find this book for sale on Amazon. He asked me to create an interactive version of the book as an app for the iPad. This is when the iPad was brand new!

Now I have finished version 2. Not only does it run on the iPad, but the iPhone and iPod Touch as well. It now has little splashes of color, some sound effects, and the page turning looks like you are turning pages in a book as opposed to flipping pages of a legal pad (which is what it looked like in version 1).

So, it is out in the app store and I know that some people that I know have bought it and left reviews. So far, in the App Store, no sales show up nor any ratings or reviews are showing up. I wonder how long it takes before those things start to be visible.

Give it a try, its only 99 cents! 🙂

If you can leave some feedback below that would be very cool too.

Here is a link:

Time Off and Some Progress on my Own Blog Software

Share this:  

Yay! I am off until the end of the year! When it comes to vacation where I work its “use it or lose it!”

Blog Software
Its on Apache, using PHP, mySQL, and a .htaccess  file. After futsing about I got the .htaccess file doing what I want for my new blog software (I am no expert on this file by any means though).

The development environment is my iMac using MAMP. I’ve got it reading a site table in my mySQL database. This software will support multiple sites on one server!

Next I’ve got to look up how to use sub-string functions in PHP. I need to take the rootPath field value from my sites table and compare it with the beginning of the URI that the user typed in in their browser. If it matches, I will set the site id, if not, I want to have some sort of fall-out page.

1 2 3 4 5 6