简体   繁体   中英

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. 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

Here is the ajax call from index.php

$('#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

    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

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

I think the line

globalSecret($secret_key);

should be

$secret_key = globalSecret();

and the function globalSecret() should be as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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