I learned a handy trick today. I wanted to provide an external javascript so other websites could display some info from my site, but then realized it would be way better if I could somehow have them call a php file instead. Well you can.

So the page call will look just like the typical javascript call, except we are calling a php file:

<script language=”JavaScript” type=”text/javascript” src=”http://www.yoursite.info/yourfile.php”></script>

Now since you are calling the php file this way you need to make the php file appear to be a javascript document so to do that you need to add a Header property like this:

Header(“content-type: application/x-javascript”);

Then you need to make sure your output is in javascript format, since that is what you are outputting. So lets look at an example php file might look like – you can use this to try it out:

<?
Header(“content-type: application/x-javascript”);
$testvar=”what’s up doc?”;
echo “document.write(\”Bugs Bunny says: <b>” . $testvar . “</b>\”)”;
?>

Then just call that file. Notice I am using php’s echo to write out the javascript code document.write – if were to just echo it it would not show up on the page calling the javascript.

Ok, now lets get even fancier. We can pass some parameters to our file in the page call:

<script language=”JavaScript” src=”http://www.yoursite.com/yourfile.php?var=elmerfudd&ID=4″></script>

Then you can pick up those parameters in your php file using $HTTP_GET_VARS[] and do whatever you want with them.

Comments 4 Comments »

I had been stuck using my work’s web-based email interface for the last 6-months, so when they finally changed servers and I was able to move back to Outlook I was thrilled! It’s just much more organized and I am used to all the handy features as opposed to web-based sites. In fact, the one I was using wouldn’t even let me search in Firefox – so I had to reopen the site in IE every time I needed to search for an old email – ugh.

Anyway, since I was getting this fresh start in Outlook, I decided that I wanted to try something new, something I had only heard of in fairy tales – keep my Inbox empty!

Outlook LogoSo I have been at it a month and I am proud to say that I only have 34 items in my Inbox at the moment! Not bad for a guy that gets 50-100 a day (another 25 in my Gmail daily) and who has a history of nearly crashing mail servers with the backlog of emails he has amassed. Put it this way – I have over 9,000 emails in my Gmail!

So how am I doing it? Simply put I try to attend to every email as it comes in and then diligently delete the email immediately after taking care of whatever it was about, and then several times a day do a sweep through the Inbox and delete out what is not needed and flag anything that I still need to complete before deleting.

I had used flags before as a way to sort through the 1,000s of emails in my Inbox to see what important things I had missed. It was pretty useful – but now with so few emails in my Inbox it becomes almost a daily task list and keeps me focused on getting the items all done so I can have the pleasure of deleting them!

I will admit that I did have to create a couple folders off to the side that I could stash away things I thought I had better keep long term – and so far I haven’t deleted any of my Sent mails or emptied my Deleted Items folder either! I guess I am still a little nervous about losing something I may have needed – but hey that was not the goal to keep those empty – the goal was to “keep my Inbox empty” and so far so good! In fact since I started typing this post I deleted another email – 33 more to go!

Comments 2 Comments »

In an earlier post I described how to use conditional comment codes to call a different stylesheet for each browser like so:

<link href=”style.css” rel=”stylesheet” type=”text/css” />
<![if !IE]>
<link href=”not-ie.css” rel=”stylesheet” type=”text/css” />
<![endif]>

At the end of the post I mentioned that you can use these comments to hide other content from each browser. I received some questions on this so I thought I better explain further.

To hide content from IE or a certain version of Internet Explorer is simple just use the appropriate comment codes anywhere on the page with the content between them like so:

The above examples will hide the content from IE or the IE version you specified in teh codes – HOWEVER it will only work that way in IE, because conditional comment codes are not read by Firefox.

So to hide content from Firefox you need to use your Firefox only stylesheet you declared in the header of your file. Whatever it is you want to hide in Firefox just wrap in a <div> with a class or id that in your Firefox stylesheet you add the css property of display: none.

So here is an example:

<div id=”hidemefromfirefox”>
CONTENT TO HIDE FROM FIREFOX
</div>

Then in your Firefox only stylesheet you declare:

#hidemefromfirefox {
display:none;
}

Comments Comments Off on Use conditional comment to hide content from Firefox or Internet Explorer

These tags will emphasize to Adsense what portion of your page Adsense should use to find relevant ads:

<!– google_ad_section_start –>
GOOD CONTENT HERE
<!– google_ad_section_end –>

You can also block off sections that you do not want to be picked up by Adsense by adding a (weight=ignore) to the start tag:

<!– google_ad_section_start(weight=ignore) –>
BAD CONTENT HERE
<!– google_ad_section_end –>

This is handy for blocking out headers, footers, sidebars, menus or whatever portions of your site don;t use your desired keywords. This can also come in handy when you post something on a blog that all of sudden changes all your ads to something wacky.

Be careful though – if you don’t provide enough content within the tags you will actual lose relevancy and may even get stuck with Public Service Ads.

Read more on section targeting from Google

If these tags are working for you – here is a great post to read, it’s a few years old but all the tips are still valid ways you can use to increase ad relevancy on your site.

Comments Comments Off on Getting more relevant Adsense ads with Section Targeting

I have always preferred including a menu file on my sites rather than repeating them on all the pages for the obvious reason that menu items sometimes change and it easier to change one file than change the links on all the pages that show that menu.

So anyway, recently I have also wanted to use CSS to highlight the active or current page the user is on using CSS, this is easy to do when the menu is on each page, but requires a little PHP when using a single menu included across your site.

So anyway here is my solution:

Here is the code for the navigation menu – I save this as a file called menu.php

<?php
$active[$current] = “class=active”;
?>

<ul>
<li <?php echo $active[1] ?>><a href=”index.php”>Home</a></li>
<li <?php echo $active[2] ?>><a href=”services.php”>services</a></li>
<li <?php echo $active[3] ?>><a href=”print.php”>print</a></li>
<li <?php echo $active[4] ?>><a href=”web.php”>web</a></li>
<li <?php echo $active[5] ?>><a href=”marketing.php”>marketing</a></li>
<li <?php echo $active[6] ?>><a href=”portfolio.php”>Portfolio</a></li>
<li <?php echo $active[7] ?>><a href=”contact.php”>Contact</a></li>
</ul>

Then, just include the menu on your pages and indicate which of the menu links you want to give the CSS style “active”:

<?php $current = 3; include(“menu.php”); ?>

Lastly, don’t forget to declare a visual style for the css class “active” to make the current page link stand out from the others.

VARIATION – You can also change the menu code slightly to make the active page not linkable at all – this will further make the current page stand out from the other menu options. Here is an example of the code you would use for the links:

<li <?php echo $active[1] ?>><?php if ($current != 1) { echo “<a href=\”index.php\”>home</a>”; } else { echo “home”; } ?></li>
<li <?php echo $active[2] ?>><?php if ($current != 2) { echo “<a href=\”web.php\”>web</a>”; } else { echo “web”; } ?></li>

Comments 2 Comments »

Comments Comments Off on Web 2.0 … The Machine Is Us/ing Us

For months I would run across this strange issue where occasionally a folder of images would appear to become corrupt. Because no matter how I tried to open the folder it would crash the program – even just trying to open the folder in the Windows Explorer would crash Explorer (Not Internet Explorer by the way – but the operating systems basic folder opening program).

The folder once it began crashing would crash no matter how I tried to access the photos – if I tried to open an image from that folder in Photoshop it would crash Photoshop. It was real frustrating and caused me to use an ftp program to view the files in the folder than I could click to edit from the ftp program and it would open fine in Photoshop. But this is far from an ideal workaround for a guy that edits photos all the time as part of my webdev livelihood.

So anyway, I found the solution the other day to what was causing Explorer and Photoshop to crash when opening these image folders.

It was a conflict between XP’s built-in thumbnail viewer in Windows Explorer and Photoshop’s “Generate Thumbnail” feature. So to fix you need to disable the thumbnail feature for Photoshop files by:

1. Right-click on any image file
2. Choose Properties
3. Choose Photoshop image tab
4. Uncheck the “Generate Thumbnails” option

This will disable the feature for all image files – and I haven’t crashed since!

Comments 1 Comment »

I am assuming you already use a robots.txt file if not go to robotstxt.org because you need to know this stuff.

Anyway, to add your sitemap to your robots.txt file just add the sitemap line to the end of the file after all your disallow commands like so:

User-agent: *
Disallow: /somefolder/
Disallow: /somethingelse/
Sitemap: http://www.mysite.com/sitemap.php

Now next time the search engines crawl your site they will automatically find your sitemap.

If you have a new site you will should probably still submit the sitemap URL to the search engines through their webmaster interfaces or use a ping.

Submit Sitemap to Google or Ping Google with your Sitemap

Submit Sitemap to Yahoo or Ping Yahoo with your Sitemap

Submit Sitemap to MSN Live.com

Submit Sitemap to Ask.com or Ping Ask.com by hitting this address:
http://submissions.ask.com/ping?sitemap=http://www.yourdomain.com/sitemap.xml

Comments 1 Comment »

Adding some If…Then logic to our Excel formulas can really make creating dynamic spreadsheet easier.

Basically the IF logic statement in excel works just like it does in any web coding program, it check to see if a condition is met and then executes something based on the results.

It looks like this:

=IF(logical_test, value_if_true, value_if_false)

So for instance the formula:

=IF(A2>B2,”yes”,”no”)

Checks to see if Cell A2 is bigger than B2 and returns “Yes”if it is or “No” if it is not.

You can do an endless number of things with the true and false values, such as return text, return numbers, return a cell value or even execute a formula.

Lets look at some various options:

=IF(A2>B2,”yes”,”no”) — returns text answers
=IF(A2>B2,”why yes it is larger”,”no of course its not larger”) — returns longer text answers
=IF(A2>B2,1,2) — returns numeric answers
=IF(A2>B2,A2,B2) — returns cell values
=IF(A2>B2,(A2-B2),(B2-A2)) — returns nested formulas
=IF(A2>B2,”Sorry, you are at your limit”,(D2*4)) — returns combination of options

Ok, so lets take it up a notch. If you want to check more than one condition you can use an AND or an OR operator:

=IF((AND(D2>5,C2<100)),2,1)
=IF((OR(D2>5,C2<100)),2,1)

Now – you can even nest multiple AND/OR statement into the same IF formula, the difference here is that while each logic test can have its own value if True, you can only have one value if all are false. You can nest up to 7 IFs in one formula, so that means you can return up to 8 different results (7 different values if true and one value if false).:

=IF((AND(D2>5,C2<100)),3,(IF((OR(D2>5,C2<100)),2,1)))
=IF((B2=”Michigan”),4,IF((B2=”Indiana”),3,IF((B2=”Ohio”),2,IF((B2=”Illinois”),1,””))))

Notice the second example the false value is left blank “” meaning the cell will be left blank if the item is not from any of the four states listed.

Ok – go forth and be logical.

Comments Comments Off on Using IF statements in Excel formulas

A handy trick I have been using since IE 7 came out and all of sudden my css was being read a tad differently across each of these browsers: IE6, IE7 and Firefox.

Typically I first design a stylesheet for Internet Explorer, then use a conditional statement to add a second stylesheet where I only include those css items that need to be modified for non-IE browsers – namely Firefox, then I place the two stylesheet calls in the <head> like this:

<link href=”style.css” rel=”stylesheet” type=”text/css” />
<![if !IE]>
<link href=”not-ie.css” rel=”stylesheet” type=”text/css” />
<![endif]>

I list them in that order because only IE reads these codes so in IE it only reads the “style.css”, but in Firefox it reads the “style.css” first then writes over what ever styles are renamed in “non-ie.css”

Here are other conditional comments you can use and what they stand for if you need to get more exact on which browser you are targeting:

<!–[if IE]>
If browser is Internet Explorer<br />
<![endif]–>
<!–[if IE 5]>
If browser is Internet Explorer 5<br />
<![endif]–>
<!–[if IE 5.0]>
If browser is Internet Explorer 5.0<br />
<![endif]–>
<!–[if IE 5.5]>
If browser is Internet Explorer 5.5<br />
<![endif]–>
<!–[if IE 6]>
If browser is Internet Explorer 6<br />
<![endif]–>
<!–[if IE 7]>
If browser is Internet Explorer 7<br />
<![endif]–>
<!–[if gte IE 5]>
If browser is Internet Explorer 5 and up<br />
<![endif]–>
<!–[if lt IE 6]>
If browser is Internet Explorer lower than 6<br />
<![endif]–>
<!–[if lte IE 5.5]>
If browser is Internet Explorer lower or equal to 5.5<br />
<![endif]–>
<!–[if gt IE 6]>
If browser is Internet Explorer greater than 6<br />
<![endif]–>
<![if (IE 6)|(IE 7)]>
If browser is Internet Explorer 6 OR 7 ( | is the OR operator )
<![endif]–>
<![if (gt IE 5)&(lt IE 7)]>
If browser is Internet Explorer 5, 5.5 OR 7 ( & is an AND operator but with the gte and lt it is used as a BETWEEN method )
<![endif]–>

Conditional comments are preferable to weightier browser detection scripts and are cross-browser friendly, so don’t forget that you can use these conditional comments to also include or exclude whatever code you want – not just stylesheets.

Comments 1 Comment »