PHP parsing error in Drupal-based website - php

I am working on a Drupal-based website that works fine on the remote server (LAMP stack) as well as all other developer's systems (WAMP stack). But when I try to run it, the PHP code is spit out in the browser along with the HTML instead of being parsed like it should.
There's very little information that I can glean from error logs. PHP itself is installed properly and a clean Drupal installation works. It's only the code that I check out from our repository that goes awry and only on my own system.
Pretty URL's also don't work, and I have to use the /q=xxx format to get to pages at all. Pretty URL's just end up with a parsing error in weird locations when there shouldn't be any parsing error there. I reiterate - the code works well everywhere else except on my system.
Is there even some place I can begin to look to solve this problem?
.p

If you see PHP code in the html then the interpreter is not being invoked. PHP is either not installed or mis-configured. Are you using short tags? If so, do you have the short tags option enabled in php.ini?
An easy way to test this is to through out all the variables and try a simple php script outside of Drupal. Put the following in a script and run it. This could give you some idea of what's going on.
<?php
echo 'Hello World!';
?>
<?
echo 'Hello World!';
?>

If you created a node, and then used PHP code as its body, then check the input format has been set to "PHP code"; differently, the PHP code will be parsed as text, and the <?php ?> tags escaped.
This would explain why you see them.
If this is not the case, then I would check what reported by Mike B, or if files with extension .php are not considered PHP files.

Related

Raspberry Pi Apache2 Web Server - Removes all PHP code from HTML and PHP documents

I recently installed an Apache2 web server, and PHP5 on my Raspberry Pi, and hooked it to my home router. It all works fine in terms of displaying HTML, even when the index document is a .php file. However, as soon as I try to enter any PHP code, and run it through my browser, it's completely removed from the document.
<html>
<head>
<?php
$baseUser = fopen("GCusernames.txt", "a");
$newUser = $_POST['user'];
fwrite($baseUser, $newUser);
fclose($baseUser);
?>
</head>
<body>
<h1>Writing to userbase</h1>
</body>
</html>
PHP document inspected in my browser
I've tried changing it back and forth to a HTML file and scouring the internet for clues. But everything I found was seriously unclear and vague.
I'd appreciate any help at all. Thanks.
UPDATE: So after I realized how idiotic I was (thank you everyone who answered,) I now understand that the PHP code shouldn't show up in the browser anyway. Sorry about that.
However, it still doesn't explain why the code doesn't execute at all. It just goes straight to the PHP page, rather than executing it.
PHP is interpreted by the server, it is not send to the user.
Thats what PHP is for.
For Example:
You want to make a password login. You write the passwordfunction in php because the user cannot see it.
More Information on PHP
PHP is run by the server that your '.php' file lives on, in this case, your Raspberry Pi. When you request a page from your PI your PHP code will be executed before any HTML is returned to your browser.
You will never see your PHP code in your browser's inspector because your browser never even knows it existed.
If you added something like:
<?php echo "This sentence was written by PHP"; ?>
to your page, you would see the text This sentence was written by PHP in your HTML but you wouldn't see the word echo or the <?php ? tags.
There is a great piece in the PHP docs which explain the three main abilities of PHP. They also have a good guide on how to get started with PHP which may be worth checking out if you are not that familiar with it.
Further Reading:
PHP enabled page
Many people try out codecademy

issue with PHP on IIS 7.5

So I've done a bunch of research and tried a bunch of things that it'll be difficult to try and explain everything i've already done but here's my issue.
My website isn't interpreting PHP code, whether I try to use an include 'file.php'; or just input the code directly into the HTML it doesn't matter.
I'm running Windows 7 with IIS 7.5 with PHP installed from php.iis.net. I'm going to keep it simple rather than go into the specifics of exactly what I'm trying to do, and hopefully once I get the simple things working the more complex stuff I'm working on will work.
Here's the HTML piece:
Weather condition is currently <?php echo '<p>Hello world</p>'; ?>
The output is
Weather condition is currently Hello world '; ?>
The beginning bracket of the PHP is hidden, after World its showing the rest on a new line under the text.
I also have
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>
That returns nothing on the webpage, and if you look at the source code you see the full PHP code. Same with the Hello world example, the text doesn't show the ?php portion but viewing the page source you see the full php.
There's something I'm missing somewhere in the IIS config or the PHP config and I'm just not finding it.
Any insights or ideas I'm open to try. This is a fresh IIS and fresh PHP install, I installed IIS on this workstation specifically to get this PHP script to work so it is doing nothing else but hosting this web page.
thanks!

php on nginx stops executing php code

I recently set up nginx and php. PHP is running and executes index.php just fine. It will output echo "hello world!"; just fine.
However after that, I'm including several PHP files and once this happens, it starts displaying the PHP code in the browser -- not executing the code.
What can I do to troubleshoot this? Any ideas?
There was someone on serverfault with a problem i think is similar to yours, maybe worth checking: https://serverfault.com/questions/247093/getting-php-to-work-with-nginx

Stop PHP executing <? within javascript

I'm trying to implement TinyMCE, which is working fine on my test rig, but on the production server, PHP is trying to execute some '<?' tags which are in the tiny_mce.js file.
I have a file called html_editor.php, which is brought into each form which requires it using include_once. Inside html_editor, i have the following:
<script type="text/javascript" src="/Public/TinyMCE/tiny_mce.js"></script>
followed by the Tiny MCE initialization, but it's failing on that line with unexpected T_CONSTANT_ENCAPSED_STRING.
I replaced the script file with tiny_mce_src.js to find the exact code which is causing the problem, and it's:
html.push('<?', name, ' ', text, '?>');
I've swapped the single quotes with doubles in tiny_mce_src.js, which does resolve the problem, but in the minified code, they're already double.
It's obviously a configuration difference with PHP between my test and production servers, but I can't track down what. I am testing with PHP 5.3, and the server is running 5.2.
Why are JavaScript files going through the PHP interpreter?!
Fix your server configuration to only treat *.php as PHP. How to do this depends on the web server you use and how you're running PHP; can you paste your test and production configurations?
you need to edit php.ini and set
short_open_tag=0
this will stop
being processed, its a good idea regardless, then make suer all your php scripts use

How to run php in an HTML file running python?

I get an "unhandled exception" every time I try to run this standard include in an html file running python:
<?php
//add header with tabs
include('includes/templates/common/tpl_header.php');
?>
I'm trying to run it right under the body tag that looks like this:
<body py:match="body" py:attrs="h.append_class_attr(attrs, 'mcore-body')" py:with="
attrs = h.attrs_to_dict(select('#*'));
body_class = attrs.get('class', '').split(' ');
advertising_banner_html = g.settings['advertising_banner_html'];
">
... sorry but I'm not the most avid programmer, how do you get that puppy to run?!
HTML is HTML, Python is Python and PHP is PHP.
It's THREE different technologies, which cannot be mixed.
You can't "run standard PHP include" in HTML file.
You can't "run standard PHP include" in Python file.
You can run PHP code in PHP file only.
You can't run Python code in HTML file. You can run Python code in Python file only.
So, whole question makes no sense.
It seems you should forget PHP while working with Python and use Python features for including files. Of course it shouldn't be PHP file, but Python or at least HTML file
You can't "run" PHP inside Pytho.
Genshi has xi:include but that can include only local files.
It can apparently somehow be tricked into loading data from remote URLs - Here's an answer with some pointers (but no ready-made solution) how to do it.
If you manage to make Genshi fetch a remote file, you can point it to a local PHP URL: http://localhost/scripts/myscript.php Be aware however that this will start a remote PHP instance, and probably be slower than a pure filesystem lookup.
I have been in this situation myself when customizing Trac installs. The workaround I always ended up using was having a PHP script run manually or frequently through a cron job, and write into a static file that can be included using xi:include.

Categories