[英]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.