<?php
$g = $_GET['e'];
$t = "Title!";
$h = "";
$p = "";
function errorput($et,$eh,$ep) {
$t = $et;
$h = '<h1>'.$eh.'</h1>';
$p = '<p>'.$ep.'</p>';
}
if ($g == "nodata") {
errorput("Missing Something...", "Blank Field", "You left a box or few empty.");
} elseif ($g == "nopass") {
errorput("Password Incorrect!", "Encrypted Hash Unmatched", "Your password is probably wrong.");
} else {
errorput($t, "I have no idea.", "There was an error, but we don't know why.");
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $t ?></title>
<head>
<body>
<?php echo $h; echo $p; ?>
</body>
</html>
So, it outputs html based on what it receives via GET. Why doesn't it work?
$t and others aren't in global scope. Return them.
<?php
$g = $_GET['e'];
$t = "Title!";
$h = "";
$p = "";
function errorput($et, $eh, $ep)
{
$t = $et;
$h = '<h1>' . $eh . '</h1>';
$p = '<p>' . $ep . '</p>';
return array(
$t,
$h,
$p
);
}
if ($g == "nodata") {
$errors = errorput("Missing Something...", "Blank Field", "You left a box or few empty.");
} elseif ($g == "nopass") {
$errors = errorput("Password Incorrect!", "Encrypted Hash Unmatched", "Your password is probably wrong.");
} else {
$errors = errorput($t, "I have no idea.", "There was an error, but we don't know why.");
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php
echo $errors[0];
?></title>
<head>
<body>
<?php
echo $errors[1] . $errors[2];
?>
</body>
</html>
You are trying to use variables from outside the function inside the function which won't work like you think it is.
Please read up on variable scope: http://php.net/manual/en/language.variables.scope.php
If you changed your function to have:
At the top this would work how you want it to but it is wrong.