browser won't render php code

Problems with the Windows version of XAMPP, questions, comments, and anything related.

browser won't render php code

Postby reggyonel » 14. September 2010 01:50

new to apache, php and xampp. just intalled Xampp...i'm trying to run some sample code from the book i'm using to teach myself and it won't display correctly when opening the .php file in Firefox.
this is the code:
<?php
echo "<p>Order Processed</p>";
?>

for which the browser displays:
Order Processed
"; ?>

if i try:
<script language="php">
echo "<p>Order Processed</p>";
</script>

it displays nothing. also, when i try this:
<?php
echo "<p>Order processed on ";
echo date("H:i, jS F Y");
echo "</p>";
?>

the browser displays:
Order processed on "; echo date("H:i, jS F Y"); echo "
"; ?>

if a try the code above using the tag style <script>...</script> it also displays nothing.
what am i missing?
reggyonel
 
Posts: 3
Joined: 14. September 2010 01:23

Re: browser won't render php code

Postby Altrea » 14. September 2010 04:59

HOW did you open the files in Firefox?
What URL is in your Browser Adress Bar?
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: browser won't render php code

Postby reggyonel » 14. September 2010 12:30

i just open the html/php document from Firefox: File->Open File->document.php the address in the address bar is as follows:
file:///C:/Documents%20and%20Settings/Reggy%20Agosto/My%20Documents/MyWebSites/PHPandMySQLWebDevelopment/processorder.php
reggyonel
 
Posts: 3
Joined: 14. September 2010 01:23

Re: browser won't render php code

Postby Nobbie » 14. September 2010 12:50

reggyonel wrote:file:///C:/Documents%20and%20Settings/Reggy%20Agosto/My%20Documents/MyWebSites/PHPandMySQLWebDevelopment/processorder.php


Did you EVER open a HTML or PHP file like that (file://)? Or have you ever seen before http:// instead?

The browser CANNOT interprete PHP Code neither can call any Interpreter. It simply can display HTML files and interprete HTML Tags. PHP Code is a comment from the view of a browser. PHP code is interpreted by an PHP interpreter, which is started by a webserver, like Apache for example. Therefore you MUST trigger a HTTP Request, instead of simply opening a file from your disk (this is really ridicilous).

Copy the PHP Scipt processer.php to the DocumentRoot folder of your Apache (i.e. c:/xampp/htdocs) and then open it via http://localhost/processor.php (you may simply click on this link, if you are doing it right, it opens your document as expected). And then URGENTLY get you some tutorials about the basics of webserver development and PHP Scripting. The book you are using NEVER tells you to open a PHP Script like you did.
Nobbie
 
Posts: 13183
Joined: 09. March 2008 13:04

Re: browser won't render php code

Postby reggyonel » 14. September 2010 13:42

thanks a lot...it's working
but, chill man!
like i said...you could have saved a lot of time without the rant and just give some advice.
-r
reggyonel
 
Posts: 3
Joined: 14. September 2010 01:23

Re: browser *DOES* render php code

Postby John_Buehrer » 15. September 2010 09:41

Hi,

I used to have the converse problem, my browser only showed the PHP code when connecting to the web server, or else it tried to download it as a php file. This is with MacOSX PPC, XAMPP v1.0.1, referencing a simple test URL http://localhost/phpinfo.php containing:
Code: Select all
<?php
  phpinfo();
?>


I use the older XAMPP version because I'm working with Drupal which only supports php 5.2 at this time. The problem started a few days ago when I tried to install Drupal Aegir which adds dedicated apache configuration settings at the end of httpd.conf, which still needs "some" (??) of the original XAMPP settings.

Interestingly, after removing the Aegir include in httpd.conf and restarting Apache, both FireFox and Safari still tried to download the phpinfo.php file via the test URL, which did work correctly before my Aegir tests. The Aegir installation does not modify my original httpd.conf, all changes are manually made by me.

When this problem first appeared, I experimented with httpd.conf handlers and types, but to no avail:
Code: Select all
# JDB: php handler instead of type?
##-JDB-## AddType application/x-httpd-php .php .php3 .php4
AddType application/x-httpd-php .php
##-JDB-##
##-JDB-## AddHandler application/x-httpd-php .php .php3 .php4
##-JDB-## AddHandler x-httpd-php .php .php3 .php4
##-JDB-## AddHandler php-script php


Also:
    - I have 'short_open_tag = On' in php.ini.
    - Firefox / Live HTTP headers showed 'Content-Type: application/x-httpd-php' coming my way.
    - I cleared the browser cache & cookes, restarted firefox, rebooted the Mac, restarted Apache, etc.
    - I deleted the local php sess_* cache files.
    - php.ini cache controls have mostly default values.
    - Other php sites (like this page) continue to work normally.
    - I didn't have this problem with the MAMP stack, or MacPorts AMP..

Fix:
The php module wasn't enabled after my Aegir tests. (BTW, what means 'JUSTTOMAKEAPXSHAPPY' ??)
Unconditionally loading the module fixes the problem.
Code: Select all
##-JDB-## <IfDefine PHP5>
LoadModule php5_module        modules/libphp5.so
##-JDB-## </IfDefine>

$ apachectl -t -D DUMP_MODULES 2>&1 | grep php
 php5_module (shared)


Root cause:
XAMPP Apache is normally started by the "GUI widget" or
Code: Select all
/Applications/XAMPP/xamppfiles/xampp startapache
These methods check for an available PHP version and pass the appropriate DEFINE's to httpd. However, Aegir wants to control Apache restarts itself (sudo apachectl), and since I began using this method myself, PHP5 was no longer defined to httpd nor rendered by the Browser.
John_Buehrer
 
Posts: 2
Joined: 15. September 2010 08:02

Re: browser *DOES* render php code

Postby Altrea » 15. September 2010 09:55

John_Buehrer wrote:I use the older XAMPP version because I'm working with Drupal which only supports php 5.2 at this time.

Thats not correct.
Drupal Doc wrote:PHP 5.3 is not yet supported by Drupal 5.x, but is supported by Drupal 6.14 core and higher (see the release notes for 6.14) and also by Drupal 7.x.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11935
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: browser won't render php code

Postby John_Buehrer » 15. September 2010 10:08

Sorry to disagree, but "Drupal" means more than just the core. It means the modules too, and in my case, Aegir, which "recommends" php 5.3 to avoid error messages and other things under development.

It is, but it isn't. I've noticed this a lot with Drupal; sure much stuff "is" available, but with an unmentioned caveat of excess time and effort to really make it work. (And sometimes, only "maybe" make it work.)

Regarding php 5.3, why not be honest and just admit it isn't supported (yet) by Drupal in a macroscopic sense, rather than mislead people into wasting time? People quite into the internals (like module developers) already know the inside story.
John_Buehrer
 
Posts: 2
Joined: 15. September 2010 08:02


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 84 guests