Web Analytics Made Easy -
StatCounter php & javascript - CodingForum

Announcement

Collapse
No announcement yet.

php & javascript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • php & javascript

    hello,
    I'm building a simple web logger for my site, and i want to log the client browser resolution, but i know that php can't provide this info.

    however javascript can:

    PHP Code:
    <script>
    function 
    getres(){

        
    // get browser resolution
        
    var browserName=navigator.appName
        if (
    browserName=="Netscape"){ 
            
    // Netscape/FireFox
            
    document.write(window.innerWidth+'<BR />');
            
    document.write(window.innerHeight);
        } else {
            
    // IE
            
    document.write(document.body.clientWidth+'<BR />');
            
    document.write(document.body.clientHeight);
        }
    }
    </
    script>
    <
    div onclick='getres();'>get res</div
    my question is, how can i get this data into php/mysql with out using hidden form fields, which even if i did, i'm still not sure how to get the data with out something being submitted.

    any ideas?

    thanks in advance for your time!
    -Ken

  • #2
    Originally posted by angst View Post
    hello,
    I'm building a simple web logger for my site, and i want to log the client browser resolution, but i know that php can't provide this info.

    however javascript can:

    PHP Code:
    <script>
    function 
    getres(){

        
    // get browser resolution
        
    var browserName=navigator.appName
        if (
    browserName=="Netscape"){ 
            
    // Netscape/FireFox
            
    document.write(window.innerWidth+'<BR />');
            
    document.write(window.innerHeight);
        } else {
            
    // IE
            
    document.write(document.body.clientWidth+'<BR />');
            
    document.write(document.body.clientHeight);
        }
    }
    </
    script>
    <
    div onclick='getres();'>get res</div
    my question is, how can i get this data into php/mysql with out using hidden form fields, which even if i did, i'm still not sure how to get the data with out something being submitted.

    any ideas?

    thanks in advance for your time!
    -Ken
    the page will either have to be submitted, or using ajax you can send the data to a server page wich can store the information in a db.. maybe a session variable?..

    try this.

    PHP Code:
    <?
    if(isset($_REQUEST['xy']))
    {
    session_start();
    $_SESSION['xy']['x'] = split(",",$_REQUEST['xy'])[0];
    $_SESSION['xy']['y'] = split(",",$_REQUEST['xy'])[1];
    session_write_close();
    header("location: index.php");
    }
    session_start();
    ?>
    <html><head>.....
    <script>
    <? if(!isset($_SESSION['xy']))
    {
    ?>
        var browserName=navigator.appName; 
        if (browserName=="Netscape"){ 
            // Netscape/FireFox
            var x = window.innerWidth;
            var y = window.innerHeight;
        } else {
            // IE
            var x = document.body.clientWidth;
            var y = document.body.clientHeight;
        }
        window.location = "?xy=" + x + "," + y;
    <?
    }
    ?>
    </script>
    </head>
    <body>
    x is <?=$_SESSION['xy']['x']?><br />
    y is <?=$_SESSION['xy']['y']?>
    </body>
    </html>
    <?
    session_write_close
    ();
    ?>
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

    Comment


    • #3
      hmm, this looks interesting, i'll give it a shot,

      thanks!
      -Ken

      Comment


      • #4
        nice!

        it works exactly as i need it too!
        good stuff!:-)

        just one thing, i've updated the javascript to use:

        var x = screen.width;
        var y = screen.height;

        this will get the full screen resolution, where as the other code would only get the browser window size. also this works in both IE and FireFox:-)

        thanks again!
        -Ken

        Comment


        • #5
          Originally posted by angst View Post
          nice!

          it works exactly as i need it too!
          good stuff!:-)

          just one thing, i've updated the javascript to use:

          var x = screen.width;
          var y = screen.height;

          this will get the full screen resolution, where as the other code would only get the browser window size. also this works in both IE and FireFox:-)

          thanks again!
          -Ken
          not a problem.

          sometimes the code isn't difficult but wrapping your mind around the logic can be.

          as this is not the most effecient way (i'm sure) it should work.
          public string ConjunctionJunction(string words, string phrases, string clauses)
          {
          return (String)(words + phrases + clauses);
          }
          <--- Was I Helpfull? Let me know ---<

          Comment


          • #6
            well, really this got me going, i've cleaned it up and modified it, i think it works quite well:-) but using session to capture the info was a good idea.

            and your exactly right, it's just getting the logic straight sometimes, even for simple solutions that can seem complex at first glance.

            Comment

            Working...
            X