0

Sorry my Gods, but....

I have php, file, and in this php i set the language, and include the necessary lang file:

 ...
     if ($lan=='ge') {$_SESSION['lang']='german';...} 
     if ($lan=='en') {$_SESSION['lang']='english'; ....} 
  } 
  if ($_SESSION['lang']=='english'){
    include ..english
  }else{
    include ...german

  }

I use Yshout in my site, and want to make it multilang. In the JS file the developer use some text which i have to make it multilanguage.

So in JS file the first line:

`<?php header('Content-type: text/javascript');?>

And in the php:

 <script src="/js/yshout.php" type="text/javascript"></script>

Now i can use PHP in JS file. So i try to use instead of the fix text. But no results, 'coz JS don know $text variable. If i include the language file in the JS then OK, but i have to include the necessery language file, this is not work, 'coz JS dont know the $_SESSION['lang'] varible when he run.

Which is the simplest way to tell JS which language file have to be included and how can i do that?

Thank you

2 Answers 2

2

When the client asks for /js/yshout.php a (completely) new instance of php is created on the server to handle this new request. This new instance does not share the variables of the "old" instance that served the request for the html document (including the <script ...src="yshout.php"> element).
Therefore if you want to access the session data you have to call session_start() again and (as you've already noticed) assign values to all the variables you want to use.

Sign up to request clarification or add additional context in comments.

Comments

0

Rather than using Js to include your files, you need to use PHP and modify your script. And because you have put following line in Js file, but the code is that of PHP, it won't execute:

 <?php header('Content-type: text/javascript');?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.