Headers to Send to Force a Download in PHP

It can be difficult sometimes to force a web browser to popup a dialog to let someone download a file. A lot of times with things like a pdf or Microsoft Office files (Word, Excel, etc), browsers like Internet Explorer will just open them with a sub program in the browser. This can be annoying for both the developer and user. However to be honest with you, I am not sure if this is as big of an issue as it was a few years ago (with the way browsers are changing to enhance security).

Anyway, if you want to force a browser to accept a file as a download instead of opening it, I have found it is best to just be as vague as you can in your headers so the browser wont know what to do with it besides ask the user. Below is what I have used for years and it always seems to work no matter what browser or computer you are on.

header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename="myfile.abc"');
header('Content-Length: ' . filesize('myfile.abc'));

readfile('myfile.abc');

This is something I just want to log for posterity out of an old email of mine.

Firefox 3 Download Day 2008

The new version of Firefox (version 3) is coming out on Tuesday, June 17 and they are trying to set a world record for the most downloads within a twenty four hour period.

From using the betas and release candidates, this version of Firefox is the best yet. It fixes a lot of issues with stability and memory usage; and it also passes the Acid2 test and scores a 71 out 100 on the Acid3 test (using RC3). They also made some good improvements in integrating the UI into each platform (Windows, Mac and Linux).

So if you are a Firefox fan please support them by making a point to download the new Firefox on Tuesday. You can get more details about the world record and Firefox by clicking on the image below.

Download Day 2008

 

Browsershots

This is a pretty cool service the I came across the other day. It will take screenshots of a website for from a whole list of browsers, including a lot of the older versions of Internet Explorer and Firefox. It is a neat way to get a snapshot of what your website looks like on other browsers without having to test it yourself. However it will give you no indication of what is wrong with your code if the screenshots show errors.

http://browsershots.org

Here are screenshots of this website and they look pretty good even all the way back to IE5.5.
http://browsershots.org/http://www.finefrog.com/

Browser Based Javascript Code Compactor and Formatter

This is a simple tool that can help you compact or cleanup your Javascript code without having to worry about it breaking by random code obscurities. I came across this a while ago when I was trying to compact some Javascript files into one line and I was running into errors. There are some random issues where a bit of code cannot share a line with another.

It is based on the toString and toSource methods. It gives you a glimpse of how the browser sees the code. I believe this tool only works in Firefox, but the code it produces works the same as it was originally written in all browsers.

Paste your Javascript code in the box below.

Opera’s Wii Browser is a Workout

I just got a Nintendo Wii and I have been playing with the internet features of it and I must say I am very impressed with the version of the Opera web browser on it. It seems to render pages very well, including some very advanced Javascript. The zooming works really well with the wiimote and makes any page readable; even on the old television that I have.

There only a few drawbacks I have found with the browser. The first one is that when you are trying to watch video on the Wii from a website it is only able to download as much as it has space on its internal memory; which by default is 256MB. So if you are trying to watch a particularly long video it may freeze halfway through. You can expand this memory by purchasing an SD card for it, but I just got this thing on Monday so I haven’t got a lot of accessories yet. The other drawback is that the Flash player for the Wii isn’t completely functional. So some of the more advanced Flash elements do not work properly. You really can’t blame Opera for that; Macromedia (and now subsequently Adobe) has always been very lax about releasing solid Flash plugins for non mainstream systems (i.e. Linux).

The reason the browser is a workout is that you will really wear your arm out trying to write an article like this using the wiimote, pointing at each character on the keyboard screen. I tried to write this whole article on the Wii, but I gave up after so long and just got out my laptop to finish it off. I guess one other drawback of the Opera browser on the Wii is that it doesn’t have an enter button. Which in most cases wouldn’t be a problem but some lazy (or unthoughtful) web designers don’t put submit buttons with their forms, expecting that you should just be able to hit the enter key instead.

Overall the browser is awesome and I really like playing around on the internet while sitting on my couch with a remote control in my hand.

On a side note about Opera in general; I really think Opera is very well poised to take control of a decent market share of browser usage. Opera realizes that the future of web browsing is going to be very much filled with specialized devices and less with full size computers. And they already have browsers for many mobile and specialized devices. I mean if I could do all that I can with my laptop on something that fits in my pocket, I wouldn’t own a laptop.

Microsoft is there only real competition in this market so far with the version of Internet Explorer that runs on Windows Mobile, but Opera already has a browser for Windows Mobile too, and I can bet that the Opera browser is nicer (if IE for the desktop is any indication of the mobile version).

Faking css position: fixed in Internet Explorer 6

This is a trick that I have been doing for some time, but now that Internet Explorer 7 is out and it supports position fixed in css; I think this trick will been even more useful now that it will allow web developers to take better advantage of css and at the same time not leave out the Internet Explorer 6 user base. I am posting this here because I sent this to a friend a couple days ago and thought others might be able to use it as well.

The trick is really quite basic. For simplicity I am just putting this example inline, but you can put it where you want.

First your declare your intended style for IE7 (and basically every other browser):

<style type="text/css">
  #fixed_div {
    position: fixed;
    top: 0px; /* tweak this according to placement */
    left: 0px; /* tweak this according to placement */
    /* add additional styling, etc. */
  }
</style>

Second add in your Javascript function which is going to be doing your movement for IE6:

<script type="text/javascript">
function move_box() {
    var offset = 0; // set offset (likely equal to your css top)
    var element = document.getElementById('fixed_div');

    element.style.top = (document.documentElement.scrollTop + offset) + 'px';
}
</script>

Then declare the element itself:

<div id="fixed_div">I am fixed, even in IE6</div>

Lastly, implement your fix for IE6 only:

<!--[if lt IE 7]>
<style type="text/css">
  #fixed_div {
    position: absolute;
    top: 0px; /* tweak this according to placement */
    left: 0px; /* tweak this according to placement */
  }
</style>
<script type="text/javascript">
window.setInterval(move_box, 100);
</script>
<![endif]-->

I usually put this last part right before the end of the body (I guess you could just put the whole script there). This is because you don’t want the window.setInterval to fire before your fixed div is declared. You could use the body onload but I try to stay away from that because I know it is popular for other uses on more advanced pages and I don’t want to run the risk of interfering.

Here is the whole script put together:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
 . . .
<style type="text/css">
  #fixed_div {
    position: fixed;
    top: 0px; /* tweak this according to placement */
    left: 0px; /* tweak this according to placement */
    /* add additional styling, etc. */
  }
</style>
<script type="text/javascript">
function move_box() {
    var offset = 0; // set offset (likely equal to your css top)
    var element = document.getElementById('fixed_div');

    element.style.top = (document.documentElement.scrollTop + offset) + 'px';
}
</script>
 . . .
</head>
<body>
 . . .
<div id="fixed_div">I am fixed, even in IE6</div>
 . . .
<!--[if lt IE 7]>
<style type="text/css">
  #fixed_div {
    position: absolute;
    top: 0px; /* tweak this according to placement */
    left: 0px; /* tweak this according to placement */
  }
</style>
<script type="text/javascript">
window.setInterval(move_box, 100);
</script>
<![endif]-->
</body>
</html>

NOTE: This will only work properly on pages that have a valid doctype definition. If you don’t use one [you should start or] you need to change document.documentElement.scrollTop to document.body.scrollTop in the move_box function.

You can also modify this script to apply to multiple elements by passing arguments to the function or something similar. If you are doing multiple elements on a single page, you may want to consider setting up some kind of Javascript array that tracks what elements need to be corrected, this could save you from having multiple window.setInterval instances running.

Firefox 2.0 beta 2

The new Firefox beta just came out and I have been playing with it a little and to be honest with you I am not that impressed with the changes over the last beta.

The visual enhancements that you can clearly see (ie, shadowed mouseovers on new sleeker icons), are really not that impressive. Personally I think the new icons and such look pretty cheesy, hopefully they will be cleaned up more by the time the browser comes out.

I didn’t really test out the anti-phishing alerts because I am not really sure where to go on the web to get solicited. However I do think the idea is a good one and I hope they pull it off well. Only time will tell here.

As far as enhancing the search bar in the top right corner; the suggest feature appears to be nothing more than a drop down of terms you have previously typed in. It doesn’t seem that intuitive. I do however like the idea of offering search extensions from a web page, much in the same way a developer can advertise to a browser an rss feed or a favicon. But, I couldn’t really test this out to see how it worked.

Also being able to resume your browser session is a nice feature, but it is one that I really don’t much care to use. The only reason I got to experience it with this beta is because it crashed a couple of times. But I am sure they will have that fixed up before they release it though (it is just a beta after all).

The new add-ons manager looks promising but you really can’t tell if it is any good because you can’t install any extensions. This is because of the compatibility restrictions and the lack of 2.0 extensions (this is just because the browser is not out yet). I have also always thought that it would be nice if you could search and browse the themes and extensions within the context of the options menu; instead of it just launching a new window.

The bottom line is that Firefox 2.0 is going to be a great step of improvement from Firefox 1.5, but this beta is nothing to get excited over.

Here is a review I read that inspired the post.
http://www.desktoplinux.com/news/NS3852026030.html

Here is where to get a copy of the beta to try for yourself. Just be careful, it is not a finished product.
http://www.mozilla.org/projects/bonecho/all-beta.html

Firefox 2.0 beta 1

The other day I saw this eWeek article commenting on the first beta release of Firefox 2.0. The article pretty well sums up my thoughts on the beta as well. Which is that not too much has changed for the user interface except that the tab closing icon has been moved from the right side of the window and onto the right side of the tab. Which I consider a good thing (however I have long since gotten past accidentally closing the wrong tab). They have also improved the extentions and plugins interface, but I didn’t really play around with it all that much myself.

However the one user interface feature they are adding to Firefox 2.0 that I think will keep Firefox’s features ahead of Internet Explorer (even IE7) is that addtition of the inline spell checker for form inputs. It will allow you to spell check forms before you submit them; which is a great feature for a blog or other community web system. This feature has been enjoyed by other browsers (i.e. Konqueror) for some time, but I think by Firefox adding the feature it will be a huge visual thing that will help convince the average computer users to leave Internet Explorer behind. And lets face it Firefox is the forerunner in converting average computer users away from Internet Explorer, so it needs all of the niceties it can get (despite where the inspiration may have come from).

They have also done a lot of work to improve the application efficiency. To be honest with you though, I have never found Firefox to be running noticeably slow. However the computers that I use have relatively new processors and a gigabyte or more of RAM.

Security is also tightented down as well; but you really wouldn’t expect anything less considering their track record. They have had six releases in less than a year since their last major release. Microsoft definitely can’t say the same thing (IE6 released August 2001).

Firefox 1.5 - November 29, 2005
Firefox 1.5.0.6 - August 2, 2006

Unfortunately Firefox 2.0 will not pass the Acid 2 test, but its standards compliance is improved some and still far outshines Internet Explorer 6 (and I imagine IE7 as well). Hopefully by the time Firefox 3.0 rolls around they will have compliance shored up well enough to pass the test. Right now Safari 2, Opera 9 and Konqueror 3.5; as well as a few obscure browsers (iCab, maybe a few others) are the only ones that pass the test.

Here is the link to download the beta. I encourage anyone to give it a test drive.
http://www.mozilla.org/projects/bonecho/all-beta.html

Here is a link to the Firefox Roadmap. It will give you an idea of when the next release will be.
http://www.mozilla.org/projects/firefox/roadmap.html

Way to go Microsoft Internet Explorer 7

This may be one of the very few times that I will ever praise Microsoft for their work in the web browser industry. And quite honestly I am only praising them out of the fact that they are finally fixing one of Internet Explorer’s most abused bugs (i.e. It would have been truly better if they didn’t have the bug in the first place).

I am talking about the Star-HTML hack (I apologize for not having a better reference article) in Internet Explorer. Which is where you can add a ‘*’ in front of your CSS selector inside of a style tag and it will only be applied in Internet Explorer.

<style type="text/css">
  /* Will only be rendered in IE */
  * html {
    border: none;
    height: 100%;
    margin: 0px;
    padding: 0px;
    width: 100%;
  }
</style>

Apparently Internet Explorer 7 has corrected this issue so that it ignores the syntactically bad code just like most other browsers. Which I would say is a good thing. However there is a bit of an uproar brewing about it being removed because so many developers have come to rely on it to get their webpages to look right in both IE and Non-IE browsers.

Personally I welcome the fix and think that people who have relied on a hack composed of syntaxtically incorrect code should not be surprised that it has finally caught up with them. Even Microsoft gets around to fixing its bugs from time to time. Personally, I don’t understand why anyone writes syntactically bad code to target IE when you can use conditional comments (which have been around since IE 5) to add specialized styles, extra Javascript, ActiveX components, etc.

However in all fairness Internet Explorer 6 was released almost two years ago (August 6, 2004), which is a tremendous amount of time when it comes to the web (which is part of the reason why IE is so insecure and has such standards compliance problems; it is very outdated in comparison to other browsers). So I can understand that many developers have come to rely on certain things to be a constant and may have many pages to fix.

Internet Explorer 7 also boasts what seems to be a decent jump up in standards compliance. It is hard for me to say specifically what has improved; I have just noticed that when I layout pages, IE 7 beta 2 renders them a lot closer to Firefox, Opera and Konqueror without custom styles.

Another thing that I am glad that Microsoft is finally fixing in their browser is the support for PNG (Portable Network Graphic) transparency. However I am by no means applauding them on this effort because many other browser have had full support for quite some time and the format has been standardized since October 1996. I am just glad that once the browser is released and in time I will finally be able to leave behind GIF’s (a graphic format from the late 1980’s) and stop doing DOM based workarounds.

This is a poll that is going on about the Star-HTML hack. If you understand the concept I encourage you to vote (if you have not already).
http://www.positioniseverything.net/articles/poll/star-html.php

Fun with browser bugs

About a week or so ago I came across this blog put together by a fairly well known internet security guru that is currently exposing one browser security bug for every day of this month (July 2006). He is providing proof of concept code to illustrate the errors/vulnerabilities but is not providing the means to exploit them (you have to figure that out for yourself).

Not surprisingly Microsoft’s Internet Explorer has already managed to sneak itself on there ten out of twelve days so far. Many of these bugs Microsoft has already been aware of (since March) and has yet to do anything about it. This is a great example why you should switch to any browser other than Internet Explorer.

The other two browsers mentioned thusfar are Mozilla Firefox and Apple’s Safari. However Firefox’s bug has already been fixed and released in its latest version.

It will be interesting to see how the bug count turns out, browser to browser. It has been reported that he has issues for many browsers including Internet Explorer, Firefox, Safari, Opera and Konqueror. I get the feeling that the results might come out just a little one-sided.

Here is the link to the blog where the code is being posted:
http://browserfun.blogspot.com/

{
}