Recent Posts

Showing posts with label output. Show all posts
Showing posts with label output. Show all posts

How to solve: Code doesn't run/what looks like parts of my PHP code are output

If you see no result from your PHP code whatsoever and/or you are seeing parts of your literal PHP source code output in the webpage, you can be pretty sure that your PHP isn't actually getting executed. If you use View Source in your browser, you're probably seeing the whole PHP source code file as is. Since PHP code is embedded in <?php ?> tags, the browser will try to interpret those as HTML tags and the result may look somewhat confused.

To actually run your PHP scripts, you need:

a web server which executes your script
to set the file extension to .php, otherwise the web server won't interpret it as such*
to access your .php file via the web server
* Unless you reconfigure it, everything can be configured.

This last one is particularly important. Just double clicking the file will likely open it in your browser using an address such as:

file://C:/path/to/my/file.php
This is completely bypassing any web server you may have running and the file is not getting interpreted. You need to visit the URL of the file on your web server, likely something like:

http://localhost/my/file.php
You may also want to check whether you're using short open tags <? instead of <?php and your PHP configuration has turned short open tags off.