I have this codes in a php file (init_js.php):

<script>
<?php    
    $idx = $_GET['id']; 
    $APP_WEB_PATH = APP_WEB_PATH;   
?>
    var idx =  '<?=$idx?>';
    var APP_WEB_PATH = '<?=$APP_WEB_PATH?>';

</script>

Then I import this file to a php page (branch.php). When I view source I can see

var idx = '7';
var APP_WEB_PATH = 'http://zzzz.com/dev';

Is there a way to prevent this situation. Your help is kindly appreciated.

If you use AJAX yes, you can, because it would be managed by a remote PHP script and sessions. But to get more help explain better your goal.

The purpose is to make the PHP variable accessible to JavaScript. When you mention AJAX call does it apply to my concept? In other words I make a single call to init_js.php to convert the PHP variable to JavaScript variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.