PDA

View Full Version : Delivering an image through PHP



KLB
02-12-2007, 09:17 AM
I need to be able to cause a php file to deliver a "dynamic" image kind of like you see from vBulletin and web bugs. What I want to do is use a JavaScript to write in a web bug that contains screen resolution information (e.g. webbug.gif?R=800x600). This information would be then written to a text file that I could look at to figure out what percentage of my users are using resolutions less than 1024x768. The returned image would be a blank 1x1 GIF. I don't want to use a third party hosted solution to do this tracking for me.

According to http://TheCounter.com around 15% of users are still using 800x600. As I have a very high corporate and academic user base, what I'm hoping to find is that less than 5% of my user base uses 800x600 or smaller. If this is the case, I could change my site layout from 756px wide to 990px wide.

There are some sections of my site that really need to go to a wider format than the 756px I currently have my pages locked to and having dynamic width pages is not an option. If I could go to a 980px wide format some usability issues I'm running into with new features I'm rolling out would go away.

Forcing 15% of my users to horizontally scroll is not desirable, but once the percentage of my users still using something less than 1024x768 drops below 5% I feel that I can make the layout change I want.

An example of the issue I am having is on http://environmentalchemistry.com/yogi/hazmat/placards/class2-chemicals.html , because of the necessary width of the "49CFR Hazardous Materials Table and the available width of my content area I have to cause the table to horizontally scroll. Restructuring the layout to eliminate the left hand ads and/or the right hand menu is not an option. Increasing the width of the page layout would allow me to increase the width of the content area by 200px, which would resolve the horizontal scrolling issue.

Chris
02-12-2007, 10:14 AM
In my experience corporate & school usage is for LOWER resolutions, not higher resolutions. The reason is that when you're buying or replacing hundreds to thousands of monitors you tend to be more apt to cut costs by getting smaller ones.

Or if your lab budget is limited you might go more years without upgrading.

Thank being said, I believe the main thing in having php generate an image is having the appropriate header/mimetypes sent in the php file.

Though you know, you can get resolution data with javascript based trackers like Google Analytics

Westech
02-12-2007, 11:22 AM
I'm not sure why you want to bring an image into it. Couldn't you get the same result by just loading a php file in an invisible iframe? i.e., use javascript to generate the html to display getres.php?r=<resolution> in an invisible iframe, then have getres.php store the results in a file or db?

Or, it might be possible to use some kind of clever ajax method to have your html page call a php script and send the user's resolution without using an iframe or image at all.

KLB
02-12-2007, 11:31 AM
I was just thinking that an image tracker would be the cleanest way to do it and it would give me a chance to learn how to create images on the fly.

rpanella
02-12-2007, 02:32 PM
The simplest way as Chris stated would be to use Google Analytics, which gives tons of other useful data as well. I would recommend trying it out if you have never used it before.

As far as using php to do it as you suggested, the easiest way is to simply redirect to a static image of your choice after the logging is complete using header() ie:


header("Location: http://www.mysite.com/blankpixel.gif");

If you wanted to show a dynamic image that changes based what you passed to the PHP script, it is a little more complicated and you would print out the actual image data along with the appropriate headers, but if you would just like to load a blank pixel the above is the easiest.
________
Honda Sparta history (http://www.honda-wiki.org/wiki/Honda_Sparta)

KLB
02-12-2007, 02:41 PM
Thanks, the header solution seems very simple for multiple purposes.

I am giving Google Analytics a try. I mean it isn't like every page already has an AdSense ad on it so it isn't like I'm keeping any secrets from Google. ;)

I like the fact that Analytics can be tied into Google AdWords. This will help with conversion tracking on sites that I buy AdWords advertising for.

agua
02-12-2007, 05:20 PM
Ken - instantly you could give yourself 30 extra pixels by increasing your width to 785px (no horizontal scroll at 800x600).

Then I would suggest using the css selectors: max-width (set at 990px) and min-width (set at 785px).

I think you may have to do some work around in IE - but whats new there.

This way you will have a semi flexible layout catering for all screen sizes with some control over the content display.

KLB
02-12-2007, 06:49 PM
20px would do me no good. I need 200px. I also can't use any form of flexible styles like you suggest because of a host of cross browser issues especially with MSIE. As part of the SEO and accessibility design of the site the HTML code for the left hand column actually comes after the right hand menu HTML. The idea was for the important content to come first and all the detritus to come last if one was using a text only browser (take a look at my pages with CSS and JavaScript turned off).

If the percentage of 800x600 users is low enough, I am considering setting my site to the wider width I want and then using JavaScript to narrow down my layout on computers with 800x600 resolution. This could be very tedious and tricky, but it might work. I simply want to provide as good of user experience as possible for the maximum percentage of users with accessibility being a top priority.

rpanella
02-12-2007, 08:28 PM
Ken, I had the same hesitation before using Google Analytics on one of my biggest sites, thinking that giving them all the data might be a bad idea. But as you say they already have plenty of ways to collect data from my website if they wanted to, since Adsense is on basically every page, not to mention toolbar users as well as a majority of my traffic comes from them in the first place.
________
IOLITE VAPORIZER (http://vaporizers.net/portable-vaporizers)

KLB
02-12-2007, 08:34 PM
Ken, I had the same hesitation before using Google Analytics on one of my biggest sites, thinking that giving them all the data might be a bad idea. But as you say they already have plenty of ways to collect data from my website if they wanted to, since Adsense is on basically every page, not to mention toolbar users as well as a majority of my traffic comes from them in the first place.

Ya, Google probably already knows more about the traffic to my site than I do. ;)