blog
HOME · CREATIVE · WEB · TECH · BLOG
November 20th, 2008

Use Apache’s .htaccess To Accomplish Cool And Useful Tasks

One of the reasons why Apache is such a popular web server is because it's almost infinitely expandable and flexible. There are some incredibly powerful things you can do with Apache's config settings, and .htaccess is the most common way to modify those settings. Read the rest of this entry »

Digg It!  Add to del.icio.us  Add to StumbleUpon  Add to Reddit  Add to Technorati  Add to Furl  Add to Netscape

November 13th, 2008

How To Do An Outbound Link Script For Affiliate Links To Sponsors

In the last post I discussed how to do a script to randomly display banner ads on a site. The next step is how to handle the clicks on those ads (or on text ads).

You might just think you should embed the links directly in the HTML, but that's often a bad idea. Let's say your sponsor runs a special promotion that uses a special promo link code. You may have the links all throughout your site in blog posts, banner ads, sidebar text ads, etc. There will be too many things to change to take advantage of the special promotion. Having all your outbound sponsor links go through a single script will fix that problem - change things in one place and all your links are changed. Read the rest of this entry »

Digg It!  Add to del.icio.us  Add to StumbleUpon  Add to Reddit  Add to Technorati  Add to Furl  Add to Netscape

November 13th, 2008

How To Do Rotating Banner And Text Ads With PHP

If you want to have content on your site that changes every time someone loads the page there are a number of possible solutions. Most typically these are ads - either textual or graphical "banner ads", but the same solution can be used for other random content.

There are ad packages/"scripts" out there which are decent, but you should choose them carefully since moving to anything else will be time consuming once you're fully set up (so make sure you really like the package and it's easy to maintain before investing too much energy in it). The other problem with ad packages is that they're almost always database driven and I've frequently seen problems where they don't redirect the person correctly. So check out sites that use the ad package to make sure it works in the real world. Read the rest of this entry »

Digg It!  Add to del.icio.us  Add to StumbleUpon  Add to Reddit  Add to Technorati  Add to Furl  Add to Netscape

November 6th, 2008

Dynamic Content With PHP Arrays (No Databases)

You don't actually need to have a database to have some dynamic content on your site. You can use arrays instead. Let's say you want to randomly show 3 Star Wars DVD box covers from Amazon.com with links to the item on Amazon. To do that you'd need three things - 1) The title of the movie, 2) the URL of the box cover, and 3) the link to the item.

You define the values that you'll choose from in PHP arrays. To do that you do something like this...

<?php
$titles = array ("Star Wars - Episode I, The Phantom Menace", "Star Wars - Episode II, Attack of the Clones", "Star Wars - Episode III, Revenge of the Sith", "Star Wars Episode IV - A New Hope", "Star Wars Episode V - The Empire Strikes Back", "Star Wars Episode VI - Return of the Jedi", "Star Wars - Clone Wars, Vol. 1", "Star Wars - Clone Wars, Vol. 2");

$pageURLs = array("http://www.amazon.com/Star-Wars-Episode-Phantom-Widescreen/dp/B00003CX5P/ref=sr_1_4?ie=UTF8&s=dvd&qid=1225998531&sr=1-4", "http://www.amazon.com/Star-Wars-Episode-Attack-Widescreen/dp/B00006HBUJ/ref=sr_1_7?ie=UTF8&s=dvd&qid=1225998531&sr=1-7", "http://www.amazon.com/Star-Wars-Episode-Revenge-Widescreen/dp/B00005JLXH/ref=sr_1_6?ie=UTF8&s=dvd&qid=1225998531&sr=1-6", "http://www.amazon.com/Star-Wars-Episode-IV-Widescreen/dp/B000FQJAIW/ref=sr_1_5?ie=UTF8&s=dvd&qid=1225998531&sr=1-5", "http://www.amazon.com/Star-Wars-Episode-Versions-Widescreen/dp/B000FQJAJG/ref=sr_1_9?ie=UTF8&s=dvd&qid=1225998531&sr=1-9", "http://www.amazon.com/Star-Wars-Episode-VI-Widescreen/dp/B000FQVX78/ref=sr_1_10?ie=UTF8&s=dvd&qid=1225998531&sr=1-10", "http://www.amazon.com/Star-Wars-Clone-Vol-1/dp/B0006Z2LMO/ref=sr_1_12?ie=UTF8&s=dvd&qid=1225998531&sr=1-12", "http://www.amazon.com/Star-Wars-Clone-Vol-2/dp/B000BCE8Q4/ref=sr_1_14?ie=UTF8&s=dvd&qid=1225999439&sr=1-14");

$imgURLs = array ("http://ecx.images-amazon.com/images/I/51BR3RNVKZL._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/51BGV8AJ4RL._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/51RHXMVH9YL._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/517M4V93K0L._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/510GTNVNYYL._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/51CWJ6PC1KL._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/51A6GEB6SAL._SL160_AA115_.jpg", "http://ecx.images-amazon.com/images/I/51F7C82EDGL._SL160_AA115_.jpg");

$titleCount = count($titles);
$element1 = rand(0, $titleCount-1);
$element2 = rand(0, $titleCount-1);
if ($element2==$element1) {$element2 = rand(0, $titleCount-1);}
$element3 = rand(0, $titleCount-1);
if ($element3==$element1) {$element3 = rand(0, $titleCount-1);}
if ($element3==$element2) {$element3 = rand(0, $titleCount-1);}
?>

So you'll need something like that to initialize the arrays. Then you use them by displaying an image with a link to the page on Amazon.com. The code for the image and link would look something like this..

<a href="<?php echo $pageURLs[$element1]; ?>" target="amazon"><img src="<?php echo $imgURLs[$element1]; ?>" alt="<?php echo $titles[$element1]; ?>" title="<?php echo $titles[$element1]; ?>" /></a>

So the basic syntax is a PHP echo that specifies the array and the value of the element of the array. $titles[$element1] means the $title array and the element of the array is the value found in the $element1 variable. If you had put $titles[1] that would be element 1 of the array (which is actually the second element in the array since elements start their counting at zero, not 1).

So let's see it in action...

Star Wars - Episode III, Revenge of the Sith   Star Wars - Episode I, The Phantom Menace   Star Wars Episode IV - A New Hope

Now, if you take it a step further, the definition of the arrays can happen in an external file and put into the page with a PHP include. That file can be written with a database application. Which means you could have a site with dynamic content running without any databases on the web server itself.

There are many uses for this type of thing - imagine a "picture of the day" script, or a banner ad rotating script. The options are pretty wide ranging.

Digg It!  Add to del.icio.us  Add to StumbleUpon  Add to Reddit  Add to Technorati  Add to Furl  Add to Netscape

October 12th, 2008

My Personal Thoughts on 4D Summit

Last year's Summit saw 4D taking a giant leap forward with v11, but it wasn't all there (no 4D Server v11). This year's Summit was more about delivering for the real world and refinement.

4D Server v11 SQL really is pretty cool, and quite powerful. A lot of what it was about was discussed last year, but it's interesting to see cases where client/server is actually faster than a standalone/mono application. And most importantly, it's here now - not a demo of an unreleased product.

v11.3

Then there's v11.3 - If we were back in the v6.0, 6.5, 6.7, 6.8 days v11.3 would be v12 - it really does have some wonderful enhancements in terms of speed, SQL (much improved user management just to name one thing) and SVG (the new component). But the issue, IMHO, is that they didn't completely stabilize v11.2 before doing the enhancements so even 11.3 will probably be a bit of a gamble for a demanding, mission-critical app. At the same time, it's such a big upgrade it is going through a lot of QA, which is always good. It's also good that they said that there will be no new features for v11 after 11.3 - from here on it's all about bug fixes and making the product stable, though I can see them releasing new features as a component like they're doing with SVG.

4D Web 2.0 Pack v11 (the AJAX part of it)

Even though I'm all about using 4D on the web, and I know some of the guys on the 4D Web 2.0 Pack team personally, I haven't ever felt like I wanted to use 4D Web 2.0 Pack. That opinion changed at Summit this year for two reasons. 1) Brendan's mention of Javascript maturing to the point that incompatibilities aren't as huge as they used to be, and 2) Julien's presentation showed that 4D Web 2.0 Pack v11 really has matured considerably. They've had tools to help you build apps before, but their Green Tea IDE really was a big step in the right direction, though they did stress that it's just how you start your app - it doesn't handle everything you're going to want it to do.

Performance

That sorta brings up what was the main interest for me this year - performance. I have a 4D-based web site that gets over 1 million page views a month from real users, plus all the bot traffic (which is considerable - Googlebot alone is over 350,000 pages/month). The client wants to launch another site, integrated with the first one, that will be FAR larger. My rough estimates are that I'll need to support 50 million page views a month within 5 years (that's an average of 20/second). 4D's internal web server can't handle the load I have now, but I need 4D v11 to handle 50 times the current load.

After quizzing Julien Feason and Charlie Vass at a 4D Kitchen session, for high volume uses I need to avoid everything that hits the cooperative thread and hit the database engine as directly as possible - avoiding 4D code whenever possible. That means I have to avoid triggers and the 4D internal web server. Solutions like the AJAX part of 4D Web 2.0 Pack which are based off 4D's internal web sever are a problem - at least for high volume uses. That, and the fact that my client still has IE6 as their corporate standard and 4D Web 2.0 Pack doesn't fully support IE6 means that even though I now want to use AJAX part of 4D Web 2.0 Pack, my use of it will be pretty limited.

However, since you now can hit 4D's database engine directly there are plenty of other options and I'll be rewriting a fair amount of my web app in PHP which can use ODBC to hit 4D's SQL engine without going through 4D code.

4D for Flex (part of 4D Web 2.0 Pack v11)

While the AJAX part of 4D Web 2.0 Pack is a problem for me, 4D for Flex is a tool I can use, since it hits the preemptive part of 4D directly and it works just fine in IE6 (provided you have Flash 9, which as fate would have Flash 9 isn't part of my client's standard corporate build either). The session on 4D for Flex made it seem really complicated, but what I found most interesting about the session were the comments in the last 5 minutes during Q&A... First Tim said that he much preferred working with 4D for Flex than the 4D AJAX framework. Then one of the attendees chimed in saying once you get over the initial learning curve with 4D for Flex you'll love it and think of it as invaluable. He went further saying that the thinking when you work with Flex is more compatible with how you think in 4D than the thinking when working with AJAX.

The Language

One thing Laurent made very clear (without actually saying it) was that the current 4D language is dead - he literally called it "the old language" (even though there's no "new language" yet). If I understood things correctly, all those lines of code you've written in 4D will never execute in a preemptive multitasking manner. There will be a new language, it will be ECMAScript based (like Javascript and ActionScript), and that will be the language that will work in 4D's preemptive multitasking environment. What this means is that current 4D code, while it will be supported for a long time, is a bit of a liability. If you really want to get the most of 4D in the future you won't be running the code you have now.

From my perspective that means the more I do in PHP and Flex, the better. Remember, with PHP and Flex I can hit the SQL engine directly and use preemptive multitasking now, and the next version of 4D will have a code editor that supports editing PHP files, and a web server (based on Apache) that has a PHP processor built-in. So Laurent's comment last year about triggers being bad was probably more about the language used by triggers being bad. Still, getting away from the 4D language is a huge change in thinking for most of us since the current 4D language is like an old friend.

SVG

SVG was the pleasant surprise for me at Summit. I've been wrestling with EPS files that have emedded TIFFs. What I realized is that if I get SVG versions of those images I can do all sorts of things like swapping out the TIFF with a low-res JPG and even watermarking the embedded image and translating the text in the image from data.

Wrap-Up

So, from my perspective it was a useful Summit. 1) It helped clarify strategies to deal with the problems I have now. 2) It let me see that the primary remaining weaknesses in 4D (IMO) are being resolved in the next version.

Digg It!  Add to del.icio.us  Add to StumbleUpon  Add to Reddit  Add to Technorati  Add to Furl  Add to Netscape

HOME · CREATIVE · WEB · TECH · BLOG