Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP code is visible on website [duplicate]

I am in the process of learning PHP and I ran into a snag, and I feel it is because the video tutorials I am watching are from 2005 and some of the API's haven't transferred over to current standards. Long story short one of the "challenges" is to create a quiz and no matter what I do the PHP code leaks over and is printed along with the HTML.

<html>
<head><title>Chapter #4 Challenge</title></head>
<body>
<h2> Chapter #4 Quiz</h2>
<?php
$question1 = "<b>Question #1: What does the operator == mean?</b><br>
        A) <input type=radio name='q1' value='a'>Equals<br>
        B) <input type=radio name='q1' value='b'>Not Equal<br>
        C) <input type=radio name='q1' value='c'>True<br>
        D) <input type=radio name='q1' value='d'>Assignment<br>
        <input type=submit value='Submit'>
        </form><br>";
$q1answer = "d";
?>
</body>
</html>

The code outputs everything that it is supposed to but at the very end it also prints out:" "; $q1answer = "d"; ?>"

What's confusing to me is why it prints anything at all, for starters, because I am just instantiating a variable and no where am I printing it. Second, why is it displaying the PHP code as text output?

Also, for the record I am using a switch statement which prefixes the variable $question1 with the opening "form" brackets so I don't think it is because I am including it on the variable. Any thoughts would be greatly appreciated!

like image 354
Eric Avatar asked Mar 14 '12 21:03

Eric


People also ask

Why is my PHP code showing up on my page?

You've written your first PHP program, but when you go to run it, all you see in your browser is the code—the program doesn't actually run. When this happens, the most common cause is that you are trying to run PHP somewhere that doesn't support PHP.

Is PHP code visible?

PHP is a server-side programming language, meaning it is executed at the web server before the website is sent to the end-user. This is why you can't see the PHP code when you view the source code.

How to check if a cookie is set?

Use the isset() function upon the superglobal $_COOKIE variable to check if a cookie is set.


1 Answers

I am sure, your file is not with *.php extension or/and your server is not php running.

like image 133
Dudeist Avatar answered Sep 20 '22 15:09

Dudeist