[英]Running external php script from another external php script
我有我的主索引页面,该页面使用对外部php文件的ajax请求来处理用户登录数据。 在该外部php文件中,我还包括另一个处理所有功能的外部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();
});
这是外部的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'];
这是functions.php
function globalSecret(){
$secret = "This is the secret";
$secret_key = sha1($secret);
}
当我运行代码时,我只是得到一个空白的警报显示,它应该在其中显示$ secret_key变量
我认为线
globalSecret($secret_key);
应该
$secret_key = globalSecret();
函数globalSecret()应该如下所示:
function globalSecret(){
$secret = "This is the secret";
$secret_key = sha1($secret);
return $secret_key;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.