0

i want to use javascript varible in php..i refered much stackoverflow link and google but i didn't get proper solution..i also know js is client side scripting language and php is serverside..but i want js varible in php and i had also try with ajax call but i want set time zone in this file not other file so ajax call is not working in my situation.any one help me how to get same result for varible in echo and var_dump...

<html>
     <script  type='text/javascript'>
        var timezone = jstz.determine();
        var timezone=timezone.name(); 
        console.log(timezone);
        // it print 'Asia/Kolkata';
    <?php $abc = "<script  type='text/javascript'>document.write(timezone)</script>"?> 



    </script>
    <?php
      echo $abc;
      // it print 'Asia/Kolkata';
      var_dump($abc);
      // it print string '<script  type='text/javascript'>document.write(timezone)</script>' (length=65)
    ?>
</html>

any help must be appreciated..Thnks

Mayur Kukadiya
  • 994
  • 6
  • 20
  • Right-click, view source, pay attention to what the result is. – Niet the Dark Absol Apr 16 '14 at 12:40
  • Look at this question/ answer [http://stackoverflow.com/questions/1045845/how-to-call-a-javascript-function-from-php][1] [1]: http://stackoverflow.com/questions/1045845/how-to-call-a-javascript-function-from-php – Peter Frauenknecht Apr 16 '14 at 12:41
  • in view source i got Asia/Kolkata for echo and for var_dump print
    string
    ''
    (length=65)
    
    – Mayur Kukadiya Apr 16 '14 at 12:43
  • The way you are doing this is incorrect. As far as I can understand you want to access client timezone in php right? Thats why you fetching the timezone through js and then assigning to PHP variable. The best way to do this is by sending an AJAX call to PHP script with the timezone parameter and then you can access that timezone variable via $_GET. Let me know if you need detailed help on this. – Sankalp Bhatt Apr 16 '14 at 13:27

1 Answers1

1

you can use php variables to javascript but not javascript variables to php.. because javascript executes on client side and php executes on server side.. so php is executed before javascript gets executed..

So simply you cant...

the only thing you can do this by using ajax....

Nishant Solanki
  • 2,119
  • 3
  • 19
  • 32