将数组从php发送到javascript,将PHP变量解析为JS

时间:2016-09-10 21:38:54

标签: javascript php

我希望能够以这种方式从php示例中获取变量:public var $PHPVariable = "Hello World";或其他东西。但是如何在没有XML HTTP(S)请求的情况下将其发送到javascript?

PHP文件示例

<?php

    public var $secure_connection = $secure['ssl']['type']['connection']['valid_id'] // This is equal to (int)25
    public var $userRank = $_SESSION['user']['active']['secure']['rank']; // Returns Admin or Default
    public var $userFullName = $_SESSION['user']['unactive']['secure']['require']['name']['first'.'middle'.'last']
?>

JavaScript文件/文件

function get(variable, type){
    if(!empty(variable) && !empty(type)){
        if(!exist(variable)){ // the exist function will check if the public variable exist in the php setting file.
            return 'The variable does not exist!';
        }
        if(type=='output'){
            return recieve(variable, 'As String'); // the recieve function will collect the data from the public variable.
        }
        if(type=='setting'){
            return recieve(variable, 'As Setting') // returning the recieve function as a setting will basicly mean it can return anything such as string/array/integer/boolean
        }
    }else{
        return 'ERROR: Please fill in required fields!';
    }
}
if(get('secure_connection', 'setting')==25){/* Returns true */}
if(get('userRank', 'setting')=='Admin'){/* Returns true */}
if(get('userFullName', 'output')){/* Returns the variable as a string no matter what the php variable was in ex int/boolean*/}
  

请记住,我想在没有XML http(s)请求的情况下这样做!

感谢您抽出时间的帮助!理查德。

修改

我知道可以将JSON请求发送到PHP Object类,这可以解决这个问题,但它对我的网站来说不够安全,尽管它允许用户甚至将自己的排名编辑到其他排名或更改SQL Connection数据库的属性和更改行值等。只要有足够的知识使用(示例)Chrome控制台使用该功能来更改php文件内容。这将导致解决没有问题。

0 个答案:

没有答案