简体   繁体   English

从另一个外部php脚本运行外部php脚本

[英]Running external php script from another external php script

i have my main index page which uses an ajax request to an external php file which handles the user login data. 我有我的主索引页面,该页面使用对外部php文件的ajax请求来处理用户登录数据。 In that external php file i also include another external php file which handles all the functions, however the external login file is not able to use any of the functions 在该外部php文件中,我还包括另一个处理所有功能的外部php文件,但是外部登录文件无法使用任何功能。

Here is the ajax call from index.php 这是来自index.php的ajax调用

$('#ind_login_submit').on('click', function (e) {

    var vars = $("#ind_login_form").serialize(); // the script where you handle the form input.
    //alert("gu");
    var hr = new XMLHttpRequest();
    hr.open("POST", "scripts/index/ind_login_submit.php", true);
    hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    hr.onreadystatechange = function() {
        if(hr.readyState == 4 && hr.status == 200) {
            var data = JSON.parse(hr.responseText);
            for(var obj in data){
                if(obj == "error"){
                    alert(data[obj]);

                }else if(obj == "success"){
                    alert(data[obj]);
                    window.location.replace("http://localhost/site/dashboard.php");
                }
            }
            //alert(hr.responseText);
            //location.load();
        }
    };
    hr.send(vars);
    //results.innerHTML = "requesting...";
    event.preventDefault();
});

Here is the external ind_login_submit.php 这是外部的ind_login_submit.php

    header("Content-Type: application/json");
 session_start();
   include '../../connect.php';
    include '../functions.php';
    $secret_key = '';
globalSecret($secret_key);
$error_array = array('error' => $secret_key);
            $jsonData = json_encode($error_array);
            echo $jsonData; 
            exit;

if(isset($_POST['ind_login_remember'])){

    $ind_login_remember=1;
}else{

    $ind_login_remember=0;
}



$ind_login_email = $_POST['ind_login_email'];
$ind_login_password = $_POST['ind_login_password'];

And here is the functions.php 这是functions.php

function globalSecret(){

$secret = "This is the secret";
$secret_key = sha1($secret);
}

When i run the code i just get a blank alert show, where it should show the $secret_key variable 当我运行代码时,我只是得到一个空白的警报显示,它应该在其中显示$ secret_key变量

I think the line 我认为线

globalSecret($secret_key);

should be 应该

$secret_key = globalSecret();

and the function globalSecret() should be as follows: 函数globalSecret()应该如下所示:

function globalSecret(){
    $secret = "This is the secret";
    $secret_key = sha1($secret);
    return $secret_key;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM