tags:

views:

75

answers:

3

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  A: 

You cannot have two returns as you are doing. Try

return (!empty($_GET['fact']) && !empty($_GET['query']));
CogitoErgoSum
Nice nickname :) And we've got both answer in on the same second... LOL
NullUserException
Ty. How come you didn't use parenthesis around your entire return statement?
CogitoErgoSum
@CogitoErgoSum, the parenthesis are unnecessary.
Brendan Long
@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.
CogitoErgoSum
Dasa
+5  A: 

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.

NullUserException
nope it doesnt work
Dasa
@Dasa What doesn't work? What are you trying to do?
Daniel Vandersluis
@Dasa What does your form/url look like?
NullUserException
/index.php?search
Dasa
@Dasa That means `$_GET['fact']` is empty, the function returns false, and thus it should include `spash.php`. Is that not happening?
NullUserException
A: 

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");
}
Webarto
this also doesnt work
Dasa
I'm sure it works, but second one will probably produce result that you want. Your situation is confusing.
Webarto