In adding some js grids to an existing PHP application I ran into the following…
In one section of the site I need to display different content to different user roles. I can check for their role with a simple pre-built method n the PHP app, however I need to tell the JS side of things what the role is so it can display the correct content.
My first thought was to write the role to the dom in a hidden div and then retrieve it for use in JS:
<?php echo '<div id="user_role" style="display:none">5</div>'; ?>
then…
var user_role = $('#user_role').text();
But obviously this is not a good idea as anyone with access could manipulate the value in the dom and set it to whatever they like. So my question…
What’s the best way to set a user’s role for use with javascript in this sort of situation?
The real answer here is anything on the client side in javascript a user can manipulate, so your best only showing your content specific to users on the server side with your php.
Also if you where to go down the route you where showing above you dont need to go through all that code you could simply use the code below no need to go round the houses adding it to the dom.