SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting screen resolution in php

    Can anybody tell me how to detect a users screen resolution in php?

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Archbob
    Can anybody tell me how to detect a users screen resolution in php?
    You can't use javascript?

  3. #3
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Something like this?
    http://www.pageresource.com/jscript/jscreen.htm

    You could maybe use XMLHttpRequest/AJAX to do it "quietly".

  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I want to do it in php so I can render two different sites for those above a certain resolution and those below a certain resolution.

    The window href thing doesn't quite work.

  5. #5
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Archbob
    Well, I want to do it in php so I can render two different sites for those above a certain resolution and those below a certain resolution.

    The window href thing doesn't quite work.
    Did you read that whole page?

  6. #6
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    why wouldn't this work?

    Code:
        <SCRIPT language="JavaScript">
       <!--
       if ((screen.width>=1024) && (screen.height>=768))
       {
        window.location="highres.html";
       }
       else
       {
         window.location="lowres.html";
       }
       //-->
        </SCRIPT>
    You could change that to something like:

    window.location = "scriptname.php?res=low"

    or

    window.location = "scriptname.php?res=high"

    Couldn't you?

    Edit:



    You could put that script inside a PHP if statement so it only checks the first time.

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP is server-side it can not do client-side stuff.

  8. #8
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by coo_t2
    why wouldn't this work?

    Code:
    <SCRIPT language="JavaScript">
    <!--
    if ((screen.width>=1024) && (screen.height>=768))
    {
    window.location="highres.html";
    }
    else
    {
    window.location="lowres.html";
    }
    //-->
    </SCRIPT>
    You could change that to something like:

    window.location = "scriptname.php?res=low"

    or

    window.location = "scriptname.php?res=high"

    Couldn't you?

    Edit:



    You could put that script inside a PHP if statement so it only checks the first time.
    Thanks, my lack of creativity disgusts me.

  9. #9
    SitePoint Zealot _theworks's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I want to do it in php so I can render two different sites for those above a certain resolution and those below a certain resolution.
    i wouldnt recommend creating differnt pages for different screen dimensions.

    just make your design 'scalable'

  10. #10
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thats not always possible, especially since advertisement only come in a few sizes.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •