Put a list of constants common to both JavaScript and PHP in "client_server_shared.js".
'var' is required in JavaScript, and is legal (though deprecated) in PHP if inside a class. '$' to start a variable name is required in PHP, and legal in JavaScript.
var $shared_CONSTANT1 = 100;
var $shared_CONSTANT2 = 'hey';
PHP Code:
eval('class Client_server_shared{' ."\n"
. file_get_contents( 'client_server_shared.js' ) ."\n"
. '}'
. '$client_server = new Client_server_shared();'
);
echo $client_server->shared_CONSTANT1; // Proof it works in PHP.
echo $client_server->shared_CONSTANT2;
JavaScript Code:
alert( $shared_CONSTANT1 ); // Proof it works in JavaScript.
alert( $shared_CONSTANT2 );