How do I pass variables from javascript to php.

for example I have in javascript
"<script>"
"browser = navigator.appName;"
"</script>"

and i want, in php, to do "print" or "echo" the browser variable or to put it on a table in a mysql database.

how can I do it?

and don't start with php is a server side .....and javascript is a client side program because i know that, I read many forums and evrywhere somebody tell that php is server side program and bla bla bla. i dont want to know what kind of program is php or java i want to know how can i do this.

OK?

🙂 Thanks
R.

    I cannot express it any clearer than Weedpacket did, so I quote him here:

    Originally posted by Weedpacket
    The only way a Javascript function can send anything to a PHP function is if it causes the browser to request a new page from the server (usually by making the browser submit a form).

    I don't put the link to that other thread here, since it mentions the words client and server, which is exactly the reason for this behaviour.

    btw, php provides information about the browser, too. check
    $_SERVER['HTTP_USER_AGENT'] or
    get_browser()

      You could put it into a form with javascript and submit it using either the post or get method, and php could pick it up from there.

      eg.

      <?php
      
      if(!isset($_POST['Hidden'])) {
      
      ?>
      	<script language="JavaScript" type="text/javascript">
      
      	document.MyForm.Hidden.value = navigator.AppName;
      	document.MyForm.submit();
      
      </script>
      
      <form name="MyForm" action="<?=$_SERVER['PHP_SELF']?>" method="post">
      <input type="hidden" name="Hidden" value="">
      </form>
      
      <?php
      
      // End the if
      } else {
      
      echo $_POST['Hidden']; // This should display your Browser type
      }
      
      ?>
      

        dear matt_4013,

        i made my self a script that is 70% like your self, non of this works.

        if I run your script I receive in the status bar message "done but with errors". so..... I am at the begining 🙁

          Almost, Matt...

          The page is trying to submit the form before the form has been rendered in the browser, therefore spitting out object does not exist errors.

          This would work;

          <?php
          if(!isset($_POST['Hidden'])) {
          ?>
          <form name="MyForm" action="<?=$_SERVER['PHP_SELF']?>" method="post">
          <input type="hidden" name="Hidden" value="">
          </form>
          
          <script language="JavaScript" type="text/javascript">
          document.MyForm.Hidden.value = navigator.AppName;
          document.MyForm.submit();
          </script>
          
          <?php
          } else {
          echo $_POST['Hidden']; // This will display your Browser type
          }
          ?>
          

          Good luck.

            it is a progres but not a very big one 🙂

            why?
            because the echo function write on the screen "undefined"

            even if i write
            " document.MyForm.Hidden.value = "aaaaaa"; "
            echo write on de screen "undefined"
            .

            sorry but....
            😕

            lets ask the creator of php 🙂

            P.S. EviL_CodE, this script works on ypur PC or somewhere else?

              hah, it was just an example, never done anything like it before, it wasn't supposed to be a copy paste job 😉 My apologies, next time I'll actually test it and get it working 🙂

                The smartest way i've found for passing Javascript stuff to PHP is using a hidden frame.

                It's a simle idea: You call a frameset with a visible page (100%) and an invisible page (*). For having Client-Server interaction, just target some links to "invisible".

                  is very easy to tell story for kids. i don't want story i want a script make it test it and if it works tell us

                    this guy needs to learn how to LEARN! Quit demanding that people write your code for you!

                      Write a Reply...