2

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

2
  • Will do, but what if i don't get a good answer Commented Aug 19, 2010 at 18:05
  • You accept an answer if you think it solved your problem. Commented Aug 19, 2010 at 19:02

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

2 Comments

@Dasa What does your form/url look like?
@Dasa That means $_GET['fact'] is empty, the function returns false, and thus it should include spash.php. Is that not happening?
2

You cannot have two returns as you are doing. Try

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

4 Comments

Nice nickname :) And we've got both answer in on the same second... LOL
Ty. How come you didn't use parenthesis around your entire return statement?
the parenthesis are unnecessary.
@Brendan Long, in this particular case you are correct however I would be for future proofing in case a more complex set of logic is put in to determine a true false rather then putting them in later on.
0

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");
}

1 Comment

I'm sure it works, but second one will probably produce result that you want. Your situation is confusing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.