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!
Related
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
I'm trying to run a .php web application on Google Chrome, using Uniform Server. I thought that just having that installed would make PHP run, but clearly there's a lot I don't know. First off, when I opened the file from file:///C:/Users/... etc the PHP didn't execute properly. Here's the code:
<html>
<body>
Hello to you, good sir.
<?php
echo "</br> Hello there yourself.";
?>
</body>
</html>
Here's the output on the website:
Hello to you, good sir. Hello there yourself."; ?>
And here's how the <body> code looks from Chrome:
Hello to you, good sir.
<!--?php
echo "</br-->
Hello there yourself.";
Then, when I tried accessing the file from localhost, Chrome wouldn't even connect, saying:
Oops! Google Chrome could not connect to localhost
I'm aware of this question, but the OP didn't appear to have software needed to run PHP. I'm pretty sure I have the right software, but I don't know how to use it. How do I get Uniform Server to run PHP, and how do I connect to localhost from Chrome?
PHP wont work if opened directly in browser, thats not how PHP works, it needs to be run through the PHP parser.
A Step by step:
Download the Latest package
Unpack it onto desktop or C:, (somewhere your find it)
Open up the UniServerZ folder, where you unpacked it
Double click UniController.exe
Click Start Apache button - it should go green like below
Remove the junk files in UniServerZ/www
Put your PHP files inside that www folder.
Visit http://localhost to view your PHP files
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
I have installed WAMP server 2.0 with (PHP 5.4.3). After installing WAMP I have restarted all the services and can open
phpinfo() - it is showing up fine
phpmyadmin - it is also showing up fine.. i can play with database..
however when run simple php file in chrome I could see the code rather than result. below is the code i am trying..
<?php
echo "hello world";
?>
below is the link to file which I am trying to access via chrome.
file:///C:/WAMP/www/hello%20world.php
Make sure you have started apache
Try http://localhost/hello_horld.php
To run this script, start a browser use URL http://localhost/your_file.php or http://127.0.0.1/your_file.php
PHP is a server-side technology (instead of client-side technology like JavaScript). The PHP statements <?php ... ?> are processed in the server, and the results returned to the client (browser). so you need to use it through server not direct
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.