PHP itself works only on server side and does not know anything about client system except information sent to the server side by a client side in some HTTP request. That said,
using JavaScript to gather required information of the current client environment like window size is
unavoidable.
I presume the inner window width is required, because this is the
client width determining the design of the content.
Now, JavaScript gets information on the window width via the property
window.innerWidth
. This is a standard property, see
http://www.w3schools.com/jsref/obj_window.asp[
^], but there are several kinds of incompatibilities like in IE, see for example
http://www.javascriptkit.com/javatutors/static2.shtml[
^],
http://www.javascripter.net/faq/browserw.htm[
^].
To avoid incompatibilities, I would use jQuery
$(window).innerWidth()
. It's important not to forget round brackets at the end, as in jQuery this is a function.
See
http://api.jquery.com/innerWidth/[
^].
The server side can get this information in different ways; the selection of the method should depend on the design and logic of your application. It could be sent as a form submission, AJAX or URL parameters.
onwayir wrote:
Thanks, but the problem is that some mobile systems — some platforms do not support JavaScript.
At last what is the professional suggestion? (js-php or some better way?)
Lots of thanks. [OP's grammar/spelling/capitalization fixed — SA]
First, please don't post a solution, unless this is really a solution. In all other cases, use "Improve question" above, add a comment or reply to existing comment.
I don't know what's "js-php", I suspect this is nothing new, same very JavaScript combined with PHP. I don't really know browsers without PHP (except text-only ones), but the truth is, JavaScript can be even switched off. In this case, you are out of luck — the only universally accepted standard on client side is EMCAScript implemented as JavaScript. I think I already explained above why you cannot know such client-specific detail without using JavaScript.
So, what could you do. I would say, use more simple and reliable HTML/CSS design. Imagine you only use paragraphs and headers, tweak only the font styles and margin/padding styles, no absolute positioning. Will it be screen-size independent? Yes, pretty much. Such format is fluid, it will adopt to screen size itself. Likewise, you can all a lot more formatting in such device-independent manner and still be able to achieve quite a rich UI. Just keep it in mind and permanently test on different windows sizes, simply resizing your browser window.
As a free bonus, such design will be highly tolerable to browser incompatibility.
And don't be afraid to be not enough impressive to the users. Most reasonable people were already fed up with beefed-up "cool" design. People would be more happy with highly readable and functional design, not highly graphical puzzles.
—SA