Skip to content

Posts from the ‘PHP’ Category

22
Mar

Combine and cache multiple CSS files for performance

This is a simple way to get a performance boost if you’re using PHP + Apache. I am using it to boost performance on GoToQuiz. If you are not using Apache, you can still use the PHP portion of this performance enhancement.

Some quick background: maintaining your site’s CSS in multiple files is frequently useful and sometimes necessary. But including multiple CSS files results in a performance hit when your pages load, because each one requires a separate request from the user’s browser to your server. Each request has associated overhead, which can be minimized if you send all CSS in one request.

This is how you can combine your CSS files with PHP and cache them, relying on a clever bit of .htaccess modification:

Read moreRead more

22
Feb

Validate that URLs exist using jQuery / PHP

It would be nice to have a pure javascript method of validating that URLs exist.  One imagines you could use an AJAX call and verify the HTTP status code (200, 404, etc.) returned.  However, browser security does not permit cross-domain AJAX calls.  So, this method would only work if you are validating that URLs exist on the same domain.

Perhaps there is a way to use a hidden iframe to test the existence of a URL.  I am not aware of a way to get the HTTP status code of a page that loads inside of an iframe, though.  I’m not sure it is possible.  So you must rely on javascript plus a server-side programming language to perform this validation.  I chose jQuery and PHP.

Read moreRead more

17
Feb

IP Addresses and Geolocation – Using GeoIP

Did you ever wonder how some sites are able to tailor a message specifically to your city?  You might have seen these in ads: “Albuquerque mom loses 50 lbs!”  Hmm.  How did the site know you live in Albuquerque?

The answer is geolocation based on the user’s IP address.  And of course, geolocation can be useful beyond tailoring custom ad messages.  The good news?  Free geolocation functionality exists!

Read moreRead more