PHP config.php Config

December 8th, 2006

Rather than keeping two different versions of my configuration file for a website I use the HTTP_HOST variable so PHP can figure out where it’s at and use the appropriate settings. The HTTP_HOST environment variable returns the domain name the files are being served from. With a simple switch case you can setup your config so you don’t have to make any changes when going live.

It’s also handy if you have multiple domains parked on one pile of code. You can utilize HTTP_HOST to brand each of them seperately.

  1. $server=$_SERVER[’HTTP_HOST’];
  2. switch($server) {
  3. case ‘localhost’:
  4. define(”CONSTANT_NAME”, “schrodinger”);
  5. break;
  6. case ‘www.doyouknowwhere.com’:
  7. case ‘doyouknowwhere.com’:
  8. define(”CONSTANT_NAME”, “schumpeter”);
  9. break;
  10. }

<UL> walking with transition effects: unordered list loop with scriptaculous

December 7th, 2006

To iterate over a <ul> list of items I wrote up the following javascript code. It requires both the prototype & scriptaculous javascript libraries and takes advantage of scriptaculous’s combination effects: Appear, Fade, Puff, BlindDown, BlindUp, SwitchOff, SlideDown, SlideUp, DropOut, Squish, Fold, Grow, and Shrink.

It’s envoked as follows where ‘list-ID’ is the ID attribute of the list, ‘Effect-Hide’ is the scriptaculous disappear effect (such as Fade), ‘Effect-Show’ is the appear effect (such as Appear), and Time-Interval is the length of time to show the <li> item before moving on to the next one.

  1. walkList(list-ID, Effect-Hide, Effect-Show, Time-Interval);

So, here is the walkList Function. It adds an onload event, using addEvent which I borrowed from Scott Andrew, to first hide all the list items using hideAll(list-ID) then initiates the list iteration with startWalking

  1. function walkList(listID,eff1,eff2,intval) {
  2. addEvent(window, ‘load’, function() {
  3. hideAll(listID);
  4. startWalking(listID, eff1, eff2, intval);
  5. }, false);
  6. }

hideAll gets the list items, loops through, setting each to ‘ dispay=”none” ‘ to hide them all

  1. function hideAll(listID) {
  2. var ul =$(listID).getElementsByTagName(”LI”);
  3. for(var i=0;i
  4. ul[i].style.display=’none’;
  5. }
  6. }

startWalking applies the specified hide effect to one item and a show effect to the next one. Then uses setTimeout to schedule the next transition.

  1. var showNum = 0;
  2. var hideNum = 0;
  3. function startWalking(listID, eff1, eff2, intval) {
  4. var ul =$(listID).getElementsByTagName(”LI”);
  5. eval(’Effect.’+eff1+’(ul[hideNum].id,{duration:.3});’);
  6. eval(”window.setTimeout(\’Effect.”+eff2+”(\”"+ul[showNum].id+”\”)\’,1000);”);
  7. hideNum = showNum;
  8. if(showNum == (ul.length-1)) {
  9. showNum=0;
  10. }
  11. else showNum++;
  12. setTimeout(’startWalking(\'’+listID+’\',\'’+eff1+’\',\'’+eff2+’\',’+intval+’)',intval);
  13. }

Here is the demo