Jump to content


Pass JS Variables without Output Buffering or XMLHttpRequest

ob_start xmlhttprequest variables

  • Please log in to reply
1 reply to this topic

#1 rwhite35

  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationCleveland, Ohio

Posted 17 March 2015 - 08:59 PM

Hey All,

Need to pass the current window width to a PHP class which creates a slide show presentation.  The presentation image sizes need calculated for all devices including mobile and smart phone (mobile web).  


Problem is, PHP is server side and doesn't care about the windows width.  I'm using Javascript to acquire the window width and pass that value to PHP - before calling the class that create the presentation.


My workaround is using Output Buffering:

  ob_start(); //starts buffering
  var wwidth = screen.width;
  document.write(wwidth): //output
  $windowwidth = ob_get_clean(); //works
  error_log("Window width is: ".$windowwidth);
  //continue on with the rest of the script

I dislike ducking in and out of PHP like this.  And I'm not able to use Javascript XMLHttpRequest because I need the size before the class is called, on the current page.


Any alternative suggestions?

Thanks in advance

Edited by rwhite35, 17 March 2015 - 09:01 PM.

#2 requinix

  • Administrators
  • Impoverished Administrator
  • 9,823 posts
  • LocationWA

Posted 17 March 2015 - 09:48 PM

What you have there isn't actually working: $windowwidth contains the Javascript code you wrote. It wasn't evaluated. Your script is simply outputting
Window width is: <script>
  var wwidth = screen.width;
  document.write(wwidth): //output
If the PHP must have the width then you must push the user through some other page before then. No way around it.
The Reimann Zeta Function Trolley Problem | If you want to escape with me, come take my hand...

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users