I do not quite understand what you want. Do you want to use variables made in PHP by JS? Without using PHP in the middle? So I think you want to use Ajax .
Basically I've already done an old function to make an Ajax request . You can use them:
function Get(t,e,n){var s=new XMLHttpRequest;s.onreadystatechange=function(){4==s.readyState&&200==s.status?(e(s.responseText),s=void 0):s.status>=500&&(s=void 0,n(0))},t+=t.indexOf("?")>-1?"&tsmp="+Date.now():"?tsmp="+Date.now(),s.open("GET",t,!0),s.send()}
function Post(t,e,n,o){var s=new XMLHttpRequest;s.onreadystatechange=function(){4==s.readyState&&200==s.status?(n(s.responseText),s=void 0):s.status>=500&&(s=void 0,o(0))},t+=t.indexOf("?")>-1?"&tsmp="+Date.now():"?tsmp="+Date.now(),s.open("POST",t,!0),s.setRequestHeader("Content-type","application/x-www-form-urlencoded"),s.send(e)}
(b, well, I had compressed before)
And, well, you need a PHP file that echoes some of the user's value. As an example:
<?php (...) echo Usuario["privilegio"];?>
Then, using the Get
function above you can get this value that will exit the PHP file. 3 arguments are required: [URL do arquivo]
, [função de sucesso]
and [função de erro]
Get("http://localhost:8000/valor.php",function(e){
alert("Valor: "+e);//alerta "Valor: Usuario[\"privilegio\"]" do arquivo PHP
if(parseInt(e)==0){//se o privilégio do usuário é igual à 0
//yay
}
},function(){
alert("Falhou na requisição. Pode ser um delay?")
}
)
Remember to make the same if
conditon for the admin action file.