[prog] On the fly graphs with php
Dan
dan at cellectivity.com
Fri Jul 15 19:55:11 EST 2005
> Also, check for any stray spaces or anything
> outside of <? ?> tags, that could cause the header to be set wrong too.
Definitely! I've had plenty of cases where I include()d a library that
had a blank line at the end of the file, and that was enough to force
the headers to be sent.
> You could try either using a session variable, or
> serialize()/unserialize() and cookies
Note that using session cookies can have unexpected effects. For
example, are you sure that the session variable will be saved to disk
(and thus be available for the next HTTP request) before the browser
requests the image? I always assumed that session variables were saved
when the page finished, not when you called session_register().
Another common problem: if the user views several graphs in succession
and then hits the back button, are you sure the session variable will be
set to the graph he expects to see? What if the browser caches the page
but not the image. (Okay, that's a stretch, but it is possible. Have you
checked your caching headers?)
Many people who design web sites with cookies never consider these
questions, much to the annoyance of users. Not to mention the fact that
you can't count on search engines honoring cookies, some browsers may
restrict cookies on images, some users turn off cookies entirely... I
recommend never using cookies if you can reasonably avoid it.
However, it looks like you may have to use cookies, because it's bad
practice to use really long URL query strings. The only other option I
can see would be using an HTTP POST to deliver the image. (That way you
can transmit as much data as you want.) But of course that means
requesting the image without an enclosing page, which could be awkward.
Good luck. ;-)
--
Tell a man there are 300 billion stars in the universe and he'll
believe you. Tell him a bench has wet paint on it and he'll have
to touch to be sure.
- From "Murphy's Law on Technology",
http://home.swipnet.se/~w-10724/Murphytec.html
More information about the Programming
mailing list