php header printing full html code on browser - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, December 13, 2021

php header printing full html code on browser

I am making a simple API from PHP.

Code Snippet:

        elseif ($_GET["command"]="verifyconn"){
            header("Content-Type: application/json");
            $data=array("response" => "success");
            echo json_encode($data);
            exit;
        }

Whenever this is executed, I get this response on browser:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
</body>
</html>{"response":"wrong_secret"}

The whole HTML code gets printed on browser. When I remove header("Content-Type: application/json");, it gets fixed and JSON displays but in text. How can I fix it?



source https://stackoverflow.com/questions/70326381/php-header-printing-full-html-code-on-browser

No comments:

Post a Comment