XAMPP not parsing PHP - php

I just installed XAMPP 1.8.1 and have restarted my computer, started running Apache and MySQL, and created a test file in a test folder in my htdocs directory under XAMPP.
When I go to xampp/index.php, their page comes up fine. But my test file only returns the actual characters in my PHP file in the "Response" tab in firebug, but a completely blank white screen in the window. The file is definitely .php extension - can anyone help?
The crazy thing is, I had this working 6 months ago just fine and have just gotten back to it on a new install.

I think you might be using short tag <? ?> or <?= ?> instead of <?php ?>.
Check your php.ini. It locates at \path\to\xampp\php\php.ini. The short_open_tag should be On.
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable,redistributable code, be sure not to use short tags.
short_open_tag = On

Related

Php code in .tpl files (no template-engine)

I'm using no template engine, but I have an index.php file, which requires my "index.tpl" file. So I can divide php and html code. In the index.tpl file I can use the php short-syntax and everything works fine... I have so say: worked. I had to reinstall my server (my SD-card of the PI was broken) and now this way doesn't work anymore. The php-code in the .tpl-files isn't executed anymore.
How do I have to configure my apache, that the code gets executed? Strangely I never had this problems in any installation before.
UPDATE:
I just tested: php code in .html-files doesn't work either.
Make sure that the PHP short opening tags <? ... ?> are enabled :
To achieve this, just set :
short_open_tag=On
In your php.ini file and then restart your Apache server.
Source

my .PHP file doesnt seem to work

i have a rather simple .PHP file with the following code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>hello world</p>
<?php echo "test";
?>
</body>
</html>
yet when i run it all i see is "hello world", i checked firebug and it showed me this
and in chrome it simply comments the php out
am i missing something important here?
PHP is an pre-processed, interpreted language which means a web server (like apache) with the PHP interpreter installed must serve it to you. You must install a webserver on your local machine and access it via a URL like http://localhost. PHP cannot be viewed the same way as locally-served HTML files (like what happens when you double click them) through the file:// prototcol.
But never fear, it is not hard to get a webserver installed. Try something like XAMPP, which will install Apache, PHP, and MySQL for you and give you a nifty little control panel.
You seem to be missing PHP. Where is the file located? Are you trying this in a server?
If you are new to PHP I recommend you using WAMP or LAMP, it's the easiest way to start using the languague.
A quote from here PHP gets commented out by the browser
Browsers shouldn't comment out PHP, they shouldn't even see PHP.
Most likely, what you are experiencing is that the <? is not being
parsed by the PHP engine and being delivered to the browser. The
browser is then treating it as an unknown tag and ignoring it.
The solutions are:
Don't use short tags as they are not turned on for all PHP installations. If you have > <? some code change it to <?php some code
2.Make sure you are trying to run your PHP on a server that supports PHP.
Try installing XAAMP, It will install everything you need for PHP Development.
Oh! I think you're saving it as .PHP with capital letters, Don't use capital letters, Use small letters, so your file name should look something like test.php.

Web Browser shows nothing when I execute my php code

I'm starting to learn php, but at the beginning I came across with an error which I don't know how to solve it. I have installed wampserver 2.4 in my windows 7. When I tried to execute a simple file containing only an echo, nothing appeared neither an error.
What's the problem?
My code:
<?
echo "oi";
?>
In php.ini file you have no permission to use short tag
change it
from short_open_tag = Off
to short_open_tag = On
or use full tag
<?php //full php tag
echo "oi";
?>
The problem probably is that short open tag is not on.
Change it in php.ini
In the php.ini file you have to change is make sure that will be like that:
short_open_tag = On
Also, try to use <?php instead <?
Also you can do it by wamp server, click on the wamp icon, go to PHP-> PHP Extensions -> open short tags

web browser not processing PHP code as PHP code

I have Joomla installed in my computer, but recently have been writing php files that aren't related to the Joomla-managed site. For some reason, when I try to open those php files in the web browser using xampp (note: Joomla also is using xampp), the browser doesn't process the code w/in the tags as php code.
For example, after opening a basic page (a page with title "test", no content except in the body tags) in the web browser and going to the source code, the following is shows up in the source code:
<body>
<?php echo "hello"; ?>
</body>
instead of the HTML conversion. (i.e. just "hello")
Does anyone have an idea about what's going on here?
Thanks.
It's probably because PHP module isn't loaded in your apache. Be sure it is enabled
PHP is interpreted in the server, not the browser. Whatever's going wrong, you need to look at the SERVER side to resolve it.
My first guess: maybe you didn't suffix the file ".php" (so the server doesn't recognize it as a PHP file?)
Second guess: is the directory containing your PHP files configured to parse PHP?
If you have Joomla, you probably have PHP. You probably also have Apache.
So check your Apache configuration, and check your file naming conventions.
Is the file extension .php? The server doesn't magically know when you're serving php files, this is a good way to ensure it knows what you're doing.
Apache is looking into your localhost's defined root directory for files it can parse. In this case htdocs. This is the default for XAMPP. As far as Apache is concerned, it will not interpret any files outside of that folder.
if the problem in php module it better to re install php5 in to the system and it will work fine. probably the problem is in php module you should try re installing php in your system.
Just restart httpd service. It will work fine.
sudo systemctl restart httpd.service
if it has not worked please reinstall PHP once again.

Call to PHP prints source, doesn't run when called from another file

I have a quick question that I can't figure out. I've tried searching Google and following examples, but I can't find anything.
I have an HTML form that I'm trying to process with a PHP file, but when I submit the form, it merely prints the source of the PHP file, it doesn't execute it. If I run the PHP file by itself (not indirectly through the HTML button), it works fine.
HTML form header:
<form id="registrationform" name="registrationform" method="post" action="processregistration.php">
Submit button:
<button type="submit" value="Submit" >Create</button>
The PHP form is just <?php print "Hello"; /?
Again, it runs fine if I just run the PHP file, but prints the PHP file (doesn't run) when it gets called through the HTML form.
Any help is appreciated.
edit-Running locally through Coda
edit-Here is the output that I'm getting:
Output when the PHP is called through an HTML action:
</php
print "Hello";
?>
Output when I run the PHP directly through Coda:
Hello
I had the same problem and just fixed it on my coda version 1.7.4
I installed MAMP on my mac and set up the apache path under MAMP preferences to the folder where my sites are located;
/Users/yourUserName/Sites
this points MAMP's 'http://localhost:8888' address to your sites folder, if you paste that on your browser you'll now see your sites folder's content in the browser.
then, all you do is point the local site's connection settings to the site you are testing;
I was going to post an image, but I'm new to the site and wasn't allowed.
Under my site's preferences i set up the addresses as follows;
Root URL : 'http://localhost:8888/yourSiteRootFolder/'
Local URL : 'http://localhost:8888/yourSiteRootFolder/'
Remote Root : /yourSiteRootFolder/
Local Root : /Users/amartinez/Sites/yourSiteRootFolder/
I hope this is related to the problem you're having and helps you fix it.
Line #19 from Coda 1.6 Release notes:
Coda no longer tries to locally
preview a remote PHP file while
editing/previewing
Listed under "Improvement" - doubt they brought it back for the 1.7 release.
I'm running Apache2/PHP5 10.5.8 OS X (no problem reproducing your issue with Coda)
Even when running my form.html and post.php files from /Library/WebServer/Documents folder.
My sample files work fine in the Apache env....I just needed to run them through Coda to "break" them. :-)
Are you sure the html file and the php script are on a server with php support enabled?
I've never used Coda, but you need to be running it through a server (e.g. Apache + PHP). You cannot just open the file itself within Windows.
Try looking at xampp as a quick server for testing.
If it works properly, you should be viewing the PHP file on something like http://localhost/test.php instead of file:///something/test.php.
This may be because you don't have PHP installed on your server. I would check to make sure that your hosting package included PHP, pre installed.
Here are some resources to get you started with that, if not installed:
http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
http://www.php.net/manual/en/install.php
http://www.w3schools.com/PHP/php_install.asp
Edit: actually, I think I may have found it.
If you look at the starting PHP tag, you have a slash instead of a ?. If that's in your script, just change that to <?php. But it may not be, it could be that's just question format-ing.

Categories