<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xml:base="https://www.webmaster-forums.net/crss/node/1024589" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title></title>
    <link>https://www.webmaster-forums.net/crss/node/1024589</link>
    <description></description>
    <language>en</language>
          <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151215</link>
    <description> &lt;p&gt;Browsers do not send screen or window dimensions in the HTTP Request.  You must use a client side scripting language to send the information to the server.&lt;/p&gt;
&lt;p&gt;There are a few tricks.&lt;/p&gt;
&lt;p&gt;First, if you can get the information (dimensions) you need on a page before the it is required, you could store the information in a session.  They will then be available for later use, when you dynamically build your sized html.&lt;/p&gt;
&lt;p&gt;To get the information in this mannor, I recommend use of an img tag, such as:&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;echo&amp;lt;&amp;lt;&amp;lt;myHTML&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&amp;amp;lt;script type=\&quot;text/javascript\&quot;&amp;amp;gt;&lt;br /&gt;document.write &#039;&amp;lt;img src=\&quot;dimensions.gif?w=&#039;+screen.width+&#039;&amp;amp;amp;h=&#039;+screen.height+&#039;&amp;amp;amp;session=&#039;+session_id()+&#039;\&quot; alt=\&quot;\&quot; /&amp;gt;&#039;;&lt;br /&gt;&amp;amp;lt;/script&amp;amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;myHTML;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Second, if you need the information *now*, you can use the img technique above combined with a delay.  Print the page as normal with the img tag as close to the top as you can.  Stop printing when you require the dimensions/information.  Enter a loop that pauses (with sleep[250]) and checks to see if the information has obtained (in a database entry linked to the users session), or a given time (2 seconds) has elapsed.  Then resume printing you html source to the client (with or without your dimensions/information).&lt;/p&gt;
&lt;p&gt;This works because most browsers will download images even as the html source is still being downloaded.  Pausing the output of your html source, your browser should be able to request your special img tag.  When it does, you can enter the information into a database entry tied to a users session.&lt;/p&gt;
 </description>
     <pubDate>Wed, 12 May 2004 01:02:09 +0000</pubDate>
 <dc:creator>Mark Hensler</dc:creator>
 <guid isPermaLink="false">comment 1151215 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151101</link>
    <description> &lt;p&gt;If it&#039;s a new window, it should be opened to whatever size you need, sure. But it shouldn&#039;t check to see that it has and then force a resize if it&#039;s been opened in a tab instead, do you see what I mean?&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 22:19:06 +0000</pubDate>
 <dc:creator>Suzanne</dc:creator>
 <guid isPermaLink="false">comment 1151101 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151096</link>
    <description> &lt;p&gt;&amp;gt;&amp;gt;&amp;gt;a lot of people get alarmed and annoyed when their browser is resized.&lt;/p&gt;
&lt;p&gt;   New windows can/should be resized to whatever the developer/client wants, imo. For instance, if a new video window opens, and the content is 240X160, the browser needs to be resized.&lt;/p&gt;
&lt;p&gt;TM&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 21:53:09 +0000</pubDate>
 <dc:creator>TonyMontana</dc:creator>
 <guid isPermaLink="false">comment 1151096 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151093</link>
    <description> &lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;&lt;strong&gt;TonyMontana wrote:&lt;/strong&gt; &amp;gt;don&#039;t rely on screen sizes for site design&lt;/p&gt;
&lt;p&gt;  These are useful markers for centering content in dynamic design which I use to determine the borders around content.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Right, so that falls into the &quot;really need to&quot; category, and hopefully with JavaScript turned off you have it so the design will fail gracefully. &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/wink.png&quot; title=&quot;Wink&quot; alt=&quot;Wink&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;But again, screen width is NOT necessarily what people have set as their browser width and a lot of people get alarmed and annoyed when their browser is resized.&lt;/p&gt;
&lt;p&gt;I run a couple of windows with many tabs -- if you resize my browser, I have to PUT IT BACK to read my other tabs (often forums) at my preference. Trust me when I say this just makes me not think kindly of the person who deemed it necessarily to over-ride my preferences on a matter of ego. &lt;/p&gt;
&lt;p&gt;If you really, really believe that the window has to be different from what I have, give me the option through a link or form button to do the resizing if I happen to agree with you.&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 21:24:37 +0000</pubDate>
 <dc:creator>Suzanne</dc:creator>
 <guid isPermaLink="false">comment 1151093 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151091</link>
    <description> &lt;p&gt;Eskater&#039;s script is not returning screen dimensions:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;$width = &amp;quot;&amp;amp;lt;script&amp;amp;gt;sw=screen.width;&amp;amp;lt;/script&amp;amp;gt;&amp;quot;; &lt;br /&gt;$height = &amp;quot;&amp;amp;lt;script&amp;amp;gt;sh=screen.height;&amp;amp;lt;/script&amp;amp;gt;&amp;quot;; &lt;br /&gt;&lt;br /&gt;echo $width . &amp;quot; width&amp;quot;; // undefined&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;TM&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 20:36:00 +0000</pubDate>
 <dc:creator>TonyMontana</dc:creator>
 <guid isPermaLink="false">comment 1151091 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151089</link>
    <description> &lt;p&gt;I no longer run the current page, so I could be mistaken...&lt;/p&gt;
&lt;p&gt;My apologies...&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 20:30:04 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1151089 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151088</link>
    <description> &lt;p&gt;Yea, my approach in applying it was to stick within the javascript realm:&lt;/p&gt;
&lt;p&gt;&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&amp;lt;?&lt;br /&gt;$url = &amp;quot;newURL.php&amp;quot;;&lt;br /&gt;$dim = &amp;quot;&amp;amp;lt;script&amp;amp;gt; var sW=screen.width; sh=screen.height;&amp;quot;;&lt;br /&gt;$dim .= &amp;quot; location=&amp;#039;$url&amp;#039;+&amp;#039;?sw=&amp;#039;+sW+&amp;#039;&amp;amp;sh=&amp;#039;+sh;&amp;quot;;&lt;br /&gt;$dim .= &amp;quot;&amp;amp;lt;/script&amp;amp;gt;&amp;quot;;&lt;br /&gt;echo $dim;&lt;br /&gt;?&amp;gt;&lt;/code&gt;&lt;/div&gt;&#039;&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt;don&#039;t rely on screen sizes for site design&lt;/p&gt;
&lt;p&gt;  These are useful markers for centering content in dynamic design which I use to determine the borders around content.&lt;/p&gt;
&lt;p&gt;TM&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 20:20:25 +0000</pubDate>
 <dc:creator>TonyMontana</dc:creator>
 <guid isPermaLink="false">comment 1151088 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151080</link>
    <description> &lt;p&gt;The PHP will be &quot;compiled&quot; on the server, THEN sent to the browser where the JavaScript will be executed. It will then be available for JavaScript to control the page, but not PHP.&lt;/p&gt;
&lt;p&gt;Whenever possible, don&#039;t rely on screen sizes for site design. If you really need to, put it in the power of the user (who may not be using full-screen, for instance to view your site and would have worse viewing problems!) and set a cookie for the preferences.&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 18:37:12 +0000</pubDate>
 <dc:creator>Suzanne</dc:creator>
 <guid isPermaLink="false">comment 1151080 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151077</link>
    <description> &lt;p&gt;What version of PHP and web server were you using? Before posting my responce, to confirn what I thought, I placed the code by TonyMontana into a file on a server (SuSE Linux, Apache 2, PHP 4.3.3) and called it. (you can try it: &lt;a href=&quot;http://ctc.uakron.edu/greg/test01.php&quot; class=&quot;bb-url&quot;&gt;http://ctc.uakron.edu/greg/test01.php&lt;/a&gt; ).&lt;/p&gt;
&lt;p&gt;When the page was called, I did a view source, and the following is what I mentioned above. (Also received same responce on another server where I have hosting using FreeBSD and apache 1.x PHP 4.x).&lt;/p&gt;
&lt;p&gt;For this to work, the browser would have to send BACK to the server the results of the javascript so it could be executed in the PHP.&lt;/p&gt;
&lt;p&gt;I&#039;ll admit, I may be missing something, and if I am, I&#039;d like to learn it &lt;img src=&quot;https://www.webmaster-forums.net/misc/smileys/wink.png&quot; title=&quot;Wink&quot; alt=&quot;Wink&quot; class=&quot;smiley-content&quot; /&gt;&lt;/p&gt;
&lt;p&gt;-Greg&lt;/p&gt;
&lt;p&gt;PS. I modified the code and placed the following at &lt;a href=&quot;http://ctc.uakron.edu/greg/test02.php&quot; class=&quot;bb-url&quot;&gt;http://ctc.uakron.edu/greg/test02.php&lt;/a&gt;&lt;br /&gt;
&lt;div class=&quot;codeblock&quot;&gt;&lt;code&gt;&lt;span style=&quot;color: #000000&quot;&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;&amp;lt;?php&lt;br /&gt;$dim &lt;/span&gt;&lt;span style=&quot;color: #007700&quot;&gt;= \&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;&quot;&amp;amp;lt;script&amp;amp;gt; sw=screen.width; sh=screen.height;&amp;amp;lt;/script&amp;amp;gt;\&quot;;&lt;br /&gt;echo \&quot;Variable &amp;lt;b&amp;gt;dim&amp;lt;/b&amp;gt; is set to &amp;lt;b&amp;gt;\&quot; . htmlspecialchars(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$dim&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;) . \&quot;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;\n\&quot;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$width&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = \&quot;&amp;amp;lt;script&amp;amp;gt;sw=screen.width;&amp;amp;lt;/script&amp;amp;gt;\&quot;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$height&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt; = \&quot;&amp;amp;lt;script&amp;amp;gt;sh=screen.height;&amp;amp;lt;/script&amp;amp;gt;\&quot;;&lt;br /&gt;&lt;br /&gt;echo \&quot;Variable &amp;lt;b&amp;gt;width&amp;lt;/b&amp;gt; is set to &amp;lt;b&amp;gt;\&quot; . htmlspecialchars(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$width&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;) . \&quot;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;\n\&quot;;&lt;br /&gt;echo \&quot;Variable &amp;lt;b&amp;gt;height&amp;lt;/b&amp;gt; is set to &amp;lt;b&amp;gt;\&quot; . htmlspecialchars(&lt;/span&gt;&lt;span style=&quot;color: #0000BB&quot;&gt;$height&lt;/span&gt;&lt;span style=&quot;color: #DD0000&quot;&gt;) . \&quot;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;\n\&quot;;&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/div&gt;and this is the responce I got back:&lt;/p&gt;
&lt;blockquote class=&quot;bb-quote-body&quot;&gt;&lt;p&gt;Quote: Variable &lt;strong&gt;dim&lt;/strong&gt; is set to &lt;strong&gt;&amp;lt;script&amp;gt; sw=screen.width; sh=screen.height;&amp;lt;/script&amp;gt;&lt;/strong&gt;&lt;br /&gt;
Variable &lt;strong&gt;width&lt;/strong&gt; is set to &lt;strong&gt;&amp;lt;script&amp;gt;sw=screen.width;&amp;lt;/script&amp;gt;&lt;/strong&gt;&lt;br /&gt;
Variable &lt;strong&gt;height&lt;/strong&gt; is set to &lt;strong&gt;&amp;lt;script&amp;gt;sh=screen.height;&amp;lt;/script&amp;gt;&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;
 </description>
     <pubDate>Sat, 08 May 2004 17:59:31 +0000</pubDate>
 <dc:creator>Greg K</dc:creator>
 <guid isPermaLink="false">comment 1151077 at https://www.webmaster-forums.net</guid>
  </item>
  <item>
    <title></title>
    <link>https://www.webmaster-forums.net/serverside-scripting/best-way-get-screen-resolution-php#comment-1151050</link>
    <description> &lt;p&gt;I beg to differ....&lt;/p&gt;
&lt;p&gt;I set it up on a website I used before very similar to my post, and all was copasetic.&lt;/p&gt;
 </description>
     <pubDate>Sat, 08 May 2004 05:06:03 +0000</pubDate>
 <dc:creator>brady.k</dc:creator>
 <guid isPermaLink="false">comment 1151050 at https://www.webmaster-forums.net</guid>
  </item>
  </channel>
</rss>
