0

Hello there stack members,

I currently have a error report I wish to show - And Id like a static piece of html to be available for my GET errors.

Currently the way I have it

apicheck.php?key=dfdf - Displays a nice footer

apicheck.php?url=dfdf - Does not display footer as its currently referenced within the $_GET['url'] section.

What my ultimate goal is to have the html code somewhere around where the die function is as id like to have all 3 get error messages be able to display the HTML footer

Ive added the die function in so that I can keep the code separate from whats underneath

Im still quite new and this is my first type of adventure into anything like this

I wasnt too sure how to add the html anywhere else as it wouldnt be within one of the IF sections - id be grateful if someone could explain how to add it in other areas

<?php
echo "<html><head><title>Error Report</title><style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}.style1 {font-size: 9px}
-->
</style> </head><body>
<h1>API Authentication System 1.0.1 GPX</h1>
<HR size='1' noshade='noshade'>";
if(empty($_GET)){
    echo "<p><b>Error Name:</b> <u>VAR_M</u><br>";
    echo "<p><b>Description:</b> <u>No Variables Sent</u><br><br>";
}
if(empty($_GET['key'])){
echo "<p><b>Error Name:</b> <u>API_KEY</u><br>";
echo "<p><b>Description:</b>  <u>Missing API-Key</u><br><br>";
}
if(empty($_GET['url'])){
echo "<p><b>Error Name:</b> <u>URL_M</u><br>";
echo "<p><b>Description:</b>  <u>Missing URL</u><br>";
echo "</u></p><HR size='1' noshade='noshade'>
<h3 align='center' class='style1'>X Auth /1.0.1.GPX</h3>
</body>
</html>";              
die();
}
else
?>

4 Answers 4

1

If you want to make reusing the same html structure easy, you could use a function to echo it.

function echoError($name, $description) {
    echo "<p><b>Error Name:</b> <u>$name</u><br>";
    echo "<p><b>Description:</b> <u>$description</u><br><br>";
}

Making your entire code look something like this:

<html>
<head>
  <title>Error Report</title>
  <style>
<!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}.style1 {font-size: 9px}
-->
  </style>
</head>
<body>
  <h1>API Authentication System 1.0.1 GPX</h1>
  <HR size='1' noshade='noshade'>";
  <?php
    $error_found = false;
    if(empty($_GET)){
        echoError("VAR_M", "No Variables Sent");
        $error_found = true;
    }
    if(empty($_GET['key'])){
        echoError("API_KEY", "Missing API-Key");
        $error_found = true;
    }
    if(empty($_GET['url'])){
        echoError("URL_M", "Missing URL");
        $error_found = true;
    }
    if ($error_found) {
        echo "<HR size='1' noshade='noshade'><h3 align='center' class='style1'>X Auth /1.0.1.GPX</h3>";
    }
  ?>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

1

Is the footer you're referring to this text?

echo "</u></p><HR size='1' noshade='noshade'>
<h3 align='center' class='style1'>X Auth /1.0.1.GPX</h3>
</body>
</html>";

If so, just put it in a separate if statement that evaluates to true if any error condition is applicable:

if(empty($_GET) or empty($_GET['key']) or empty($_GET['url']) {
    echo "</u></p><HR size='1' noshade='noshade'>
    <h3 align='center' class='style1'>X Auth /1.0.1.GPX</h3>
    </body>
    </html>"
    die();
}

Better yet, you could include a line like $error_found = 1; inside each of your other error message conditional blocks, and then just test for $error_found when printing the footer and the die() statement. That way, if you add additional error checks you don't have to remember to also add that conditional to the final if statement.

Comments

0

You could build a string (start with an empty string and concatenate the error messages to it as you get them) and then print the string wherever you want.

$errorString = "";
if(empty($_GET)) {
    $errorString .= "<p><b>Error Name:</b> <u>VAR_M</u><br>";
...

And at the end, or wherever you want,

echo $errorString;

Comments

0

You could clean this up by putting the html sections in their own files and then including them using include "file.html"; You could alternativly simplify those echo statements by using Heredoc

Comments

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.