我正在将使用AJAX获取的表数据加载到具有数据表的表中.该逻辑使用getenv()
函数从.env文件中获取一些值.此getenv()只在某些情况下返回False,否则不返回.
我try 在浏览器中打开DataTables用来通过AJAX获取数据的URL(HTTP GET),但看起来一点问题都没有.
public function ap_FetchData()
{
$accountLibrary = new Account();
if($accountLibrary->checkIsUserLogged())
{
// do some stuff and print JSON - dummy logic
$data = [];
for($i=1;$i<=10;$i++)
{
$image = getBucketURL($i.".jpg");
$data[] = $image;
}
outPutAsJSON($data);
}
else outPutAsJSON("Your session is timed-out. Please login again.", 403);
}
有时我得到带有Bucket URL(部分)的JSON输出,有时我得到Session is Timed-out错误.然而,这种会话超时行为仅在AJAX上可见.
checkIsUserLogged
在库目录下的Account t.php中
function checkIsUserLogged(): bool
{
$sessionName = getenv("session.name"); // this is the session name stored in env file sometimes and false sometimes
// do validation and return true or false
}
GetBucketURL()位于帮助程序文件中.
function getBucketURL($key)
{
return getenv("s3bucket.url").$key;
/*
* some times this return as http://www.example.com/$key
* and
* some times it return only $key
* var_dump(getenv("s3bucket.url")) outputs (bool) false is second case
*/
}
Expected output:个
{
"http://www.example.com/1.jpg",
"http://www.example.com/2.jpg",
"http://www.example.com/3.jpg",
.
.
"http://www.example.com/10.jpg"
}
Actual problematic Output:个
{
"1.jpg",
"2.jpg",
"3.jpg",
.
.
"10.jpg"
}
Edit个
$_SERVER["s3bucket.url]
,$_ENV["s3bucket.url]
和$_SERVER["session.name]
,$_ENV["session.name]
可以完美地工作.问题似乎只出现在getenv()