PHP函数检查2个变量是否为空

Das*_*asa 2 php post get

我有一个索引页面,我希望它包含一个名为splash.php的页面,而不是display.php,当用户登陆index.php时,但是一旦用户做某事(设置变量),即用户搜索(变量")查询")我希望它包含display.php而不包括splash.php

这段代码有什么问题?

function hasGet()
{
    return !empty($_GET['fact']);
    return !empty($_POST['query']);
}

if (hasGet()) {
    include("display.php");
}

else {
    include("splash.php");
}
Run Code Online (Sandbox Code Playgroud)

这个问题应该删除

Nul*_*ion 5

只执行第一个return语句.尝试:

return !empty($_GET['fact']) && !empty($_POST['query']);
Run Code Online (Sandbox Code Playgroud)

完成您尝试执行的操作的更好方法是使用会话.

的index.php

<?php

session_start();

if (!isset($_SESSION['visited'])) {
    $_SESSION['visited'] = true;
    include 'splash.php';
} else {
    include 'display.php';
}

?>
Run Code Online (Sandbox Code Playgroud)

这种方式在用户index.php第一次访问后,$_SESSION['visited']设置为true,并且在访问期间不会显示启动页面.