开发者

PHP function to check if 2 variables are empty

I have an index page, I want it to include 开发者_开发百科a page called splash.php and not display.php when a user lands on index.php, but once a user does something (sets a variable) ie if a user searches (variable "query") i want it to include display.php and not include splash.php

What is wrong with this code?

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

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

else {
    include("splash.php");
}

This question should be removed


Only the first return statement is executed. Try:

return !empty($_GET['fact']) && !empty($_POST['query']);

A better way to accomplish what you are trying to do is use sessions.

index.php

<?php

session_start();

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

?>

This way after a user visits index.php for the first time, $_SESSION['visited'] is set to true and it won't show the splash page throughout their visit.


You cannot have two returns as you are doing. Try

return (!empty($_GET['fact']) && !empty($_GET['query']));


You might want to try this...

if($_SERVER["SCRIPT_NAME"] == "/index.php"){
    include("splash.php");
}else{
    include("display.php");
}

2.

if(!empty($_GET["fact"]) || !empty($_POST["query"])){
    include("display.php");
}else{
    include("splash.php");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜