Passing a Java variable to local PHP script.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy R.

    Passing a Java variable to local PHP script.

    Hello everyone,

    I've spent quite some time now, looking for some information on how to
    get this done, sadly none has helped me much, though.
    I have a bit of java scrpt on a webpage (.php) to aquire the screen
    resolution of the visiting user. Now I need to pass the java variable
    to another variable on the same document.

    I have a feeling, this will not be easy - as java is client- and php
    server-sided. Now, if my assumption is corect, then it will be
    neccessary to generate the page via .php on the webserver and send it
    to the browser. Once loaded, java will be executed to aquire the used
    screen resolution. These values (height/width) will have to be
    returned to the server, prob. via post. The server will now have to
    acknowledge the presence of these values and regenerate the webpage
    once more, this time using the provided values.

    I hope I've got it so far. Problem is - I don't have a clue about java
    and only basics in php. Please help me get this accomplished, abd
    don't forget: I'm not java savy.

    kind regards,

    Andy R.
  • Kevin Thorpe

    #2
    Re: Passing a Java variable to local PHP script.

    Andy R. wrote:
    [color=blue]
    > Hello everyone,
    >
    > I've spent quite some time now, looking for some information on how to
    > get this done, sadly none has helped me much, though.
    > I have a bit of java scrpt on a webpage (.php) to aquire the screen
    > resolution of the visiting user. Now I need to pass the java variable
    > to another variable on the same document.[/color]

    Firstly JavaScript != Java, they just share a name.

    What you need to do is send a 'detect' page if you don't already know
    the screensize. This will redirect to the original page passing the
    screen size.

    Create a file called screensize.php.
    <?php
    if ($_GET['screensize']) {
    $_SESSION['screensize'] = $_GET['screensize'];
    }

    if (!$_SESSION['screensize']) { ?>
    <html>
    <head>
    <script language=javasc ript>
    window.location .href="<?=$PHP_ SELF?>?screensi ze=" +
    screen.width + "x" + screen.height;
    </script>
    </head>
    <body>
    Checking screen size
    </body>
    </html>
    <?php exit();
    } ?>

    Then just include('screen size.php'); at the top of your pages. All of
    them will have $_SESSION['screensize'] set for you.

    NOTE: the user may not have their browser full screen.

    Comment

    • CountScubula

      #3
      Re: Passing a Java variable to local PHP script.

      "Andy R." <NoSpam4Me@mail inator.com> wrote in message
      news:939fda23.0 403110655.3c0b6 15a@posting.goo gle.com...[color=blue]
      > Hello everyone,
      >
      > I've spent quite some time now, looking for some information on how to
      > get this done, sadly none has helped me much, though.
      > I have a bit of java scrpt on a webpage (.php) to aquire the screen
      > resolution of the visiting user. Now I need to pass the java variable
      > to another variable on the same document.
      >
      > I have a feeling, this will not be easy - as java is client- and php
      > server-sided. Now, if my assumption is corect, then it will be
      > neccessary to generate the page via .php on the webserver and send it
      > to the browser. Once loaded, java will be executed to aquire the used
      > screen resolution. These values (height/width) will have to be
      > returned to the server, prob. via post. The server will now have to
      > acknowledge the presence of these values and regenerate the webpage
      > once more, this time using the provided values.
      >
      > I hope I've got it so far. Problem is - I don't have a clue about java
      > and only basics in php. Please help me get this accomplished, abd
      > don't forget: I'm not java savy.
      >
      > kind regards,
      >
      > Andy R.[/color]



      Don't reload the page, load a blank image,

      <IMG SRC="blank.gif" NAME="imgscreen size">

      <SCRIPT>
      // do you stuff here
      imgtime.src = "screensize.php ?w=" + varWidth + "&h=" + varHeight;
      </SCRIPT>


      then have screensize.php do something like this
      <?php

      // log your stuff here

      header("Content-type: image/gif");
      readfile("blank .gif");
      ?>
      --
      Mike Bradley
      http://www.gzentools.com -- free online php tools


      Comment

      • Chung Leong

        #4
        Re: Passing a Java variable to local PHP script.


        Uzytkownik "Kevin Thorpe" <kevin@pricetra k.com> napisal w wiadomosci
        news:4050851f$0 $11498$afc38c87 @news.easynet.c o.uk...[color=blue]
        > Create a file called screensize.php.
        > <?php
        > if ($_GET['screensize']) {
        > $_SESSION['screensize'] = $_GET['screensize'];
        > }
        >
        > if (!$_SESSION['screensize']) { ?>
        > <html>
        > <head>
        > <script language=javasc ript>
        > window.location .href="<?=$PHP_ SELF?>?screensi ze=" +
        > screen.width + "x" + screen.height;
        > </script>
        > </head>
        > <body>
        > Checking screen size
        > </body>
        > </html>
        > <?php exit();
        > } ?>[/color]

        Consider using window.location .replace(url) instead, so that the back button
        behaves more reasonably.



        Comment

        • Henk Verhoeven

          #5
          Re: Passing a Java variable to local PHP script.

          Hi Andy,

          Assuming you only need to adjust the size of some html elements to the
          screen size, you could do resizing entirely in javascript by something like:

          <HTML><HEAD></HEAD>
          <BODY onResize="scale Content()>
          <script>
          function scaleContent() {

          getElement('ite mTableDiv').sty le.height=(wind ow.document.bod y.clientHeight)-179;
          getElement('ite mTableDiv').sty le.width=(windo w.document.body .clientWidth)-130;
          }

          function getElement( elementId)
          {
          var element;

          if (document.all) {
          element = document.all[elementId];
          }
          else if (document.getEl ementById) {
          element = document.getEle mentById(elemen tId);
          }
          else element = -1;

          return element;
          }
          </script>

          <div id=itemTableDiv style='height: 300px; width: 600px; overflow:
          auto;' valign='top'>
          <?php printItemTableP art() ?>
          </div>
          <script> scaleContent(); </script>
          </BODY>
          </HTML>

          This resizes a DIV according to screen size minus (130, 179). You can
          fill in different values to make it larger or smaller, or print the
          proper values from php. It works in recent versions of both IE and
          Mozilla, (not in Nescape 4.x). Of course you need to write the
          printItemTableP art() function in php to produce the content of the div,
          or just print it some other way from php.

          This javascript will probably work on other types of html elements too,
          as long as you give each one a different id, and as long as the scaling
          is not making them too small for their own elements to fit in. Be aware
          that the second script must be AFTER the definition of the elements that
          are resized and after the functions that are called.

          Greetings,

          Henk Verhoeven,



          Andy R. wrote:
          [color=blue]
          > Hello everyone,
          >
          > I've spent quite some time now, looking for some information on how to
          > get this done, sadly none has helped me much, though.
          > I have a bit of java scrpt on a webpage (.php) to aquire the screen
          > resolution of the visiting user. Now I need to pass the java variable
          > to another variable on the same document.
          >
          > I have a feeling, this will not be easy - as java is client- and php
          > server-sided. Now, if my assumption is corect, then it will be
          > neccessary to generate the page via .php on the webserver and send it
          > to the browser. Once loaded, java will be executed to aquire the used
          > screen resolution. These values (height/width) will have to be
          > returned to the server, prob. via post. The server will now have to
          > acknowledge the presence of these values and regenerate the webpage
          > once more, this time using the provided values.
          >
          > I hope I've got it so far. Problem is - I don't have a clue about java
          > and only basics in php. Please help me get this accomplished, abd
          > don't forget: I'm not java savy.
          >
          > kind regards,
          >
          > Andy R.[/color]

          Comment

          Working...