tags:

views:

170

answers:

1

I was wondering if it's possible to verify a DIV's width and height on server side (PHP) without running any browser?

It seems it's not possible without writing a parser, which is no worth.

One Rube Goldberg way I could think of is, convert that DIV into html (using html tidy), then into PDF and then get the size. Highly inefficient. Even in that case I'm not sure how I'd set PDF page size.

The real practical problem is that I want to confirm the size of adverts created on client side. Users are charged based on size only. What could be alternate ways to verify dimensions? Don't Google and adready (www.adready.com) do something like this already?

Edited: These ads are template based and customer changes only few TEXT variables.

+2  A: 

It's definitely not possible. There is a plethora of client-side settings influencing the ways a page is rendered that you can't control. The only thing you could do is use a service like BrowserShots (http://browsershots.org) to make screenshots of what your sites look like in the most common browsers.

Edit: What you could do, on second thought, is write a JavaScript that determines the size of the elements - easy enough using a cross-browser framework like prototype using .getDimensions() - and send that data back to the server using Ajax. You would have to generate a unique id to identify the callcacks but this should be a good way. It seems a bit of an overkill to use this in a production environment but there are much more resource-consuming Javascripts built into sites every day.

Pekka
That's what I thought. But BrowserShots is not an option since I wanna check dimensions dynamically.
understack
I edited my answer, see abobe.
Pekka
@pekka: "and send that data back to the server using Ajax" : I'm already doing it but I can't verify this size data on server. Whatever I get from client side, I'd have to assume it's correct.
understack
If you fear manipulation, I am sure there are far more ways to break a dynamic DIV size check that falsifying AJAX data :) Do your customers really get to design their ads on HTML basis?
Pekka
Yes, ads are based on html templates. customer fill in few TEXT parameters which might change template ad size. On server side I get all the template text variables. And then I want to confirm the ad size.
understack
Hmm. Sounds like you have to set up a trusted machine somewhere and run a browser on it. That trusted instance then grabs the dimensions and sends the AJAX. Not impossible to do but not a run-off-the-mill task either.
Pekka