A cookie is clean, however it requires extra code to clean up stuff afterwards, no? Also, maybe setting the cookie fails, and then your left with nothing (or you have to build in a check and re-set it when it failed). Printing the JS with PHP like you described is what I usually do, or I return it as JSON if its an ajaxRequest.
On Aug 2, 1:33 pm, Michal Charemza <[email protected]> wrote: > On 2 Aug 2009, at 12:20, Christoph Pojer wrote: > > > You should use the first method, although I recommend against the use > > of <?= because it is deprecated in PHP5.3 and will be removed in PHP6. > > > I usually do it like this: > > > <script type="text/javascript"> > > (function(){ > > this.Config = <?php echo json_encode(array(...)); ?> > > })(); > > </script> > > > which creates a global variable "Config". > > Thanks: I see that for enough config variable to justify an array, a > cookie would perhaps not be suitable. However, all I'm thinking of is > a single ID-type variable. Why would a cookie not be good? > > (Also thanks for the <= tip: I wasn't aware of that) > > Michal.
