browser opening php files instead of running them
Posted by: Phil3566 (---.hsd1.ca.comcast.net)
Date: February 08, 2009 06:38AM

Hello

I downloaded wamp and verified that both php and apache work fine (using phpinfo() and [localhost] respectively). When I run a simple test script (from php.net) Mozilla asks me how I want to do with action.php and IE simply dumps the entire script verbatim to the screen. Can someone tell me how have the browser execute the action.php script?

Thanks!


form.html:
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>

action.php:
Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int)$_POST['age']; ?> years old.

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 08, 2009 07:31AM

seems fine


so goto h ttp://localhost/form.php

fill in the form and press submit...

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.hsd1.ca.comcast.net)
Date: February 08, 2009 08:42AM

Steven

I do exactly that (submit the completed form) and then the browser asks me what program to use to open action.php, instead of displaying the results.

Thanks.

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (193.120.116.---)
Date: February 08, 2009 11:11AM

are u sure u named the php form properly.. Actiin.php and not actiin.php.txt

Windows hides known extentions by default. Create a new file- in notepad and wen saving type

Filename action.php
Type All FIles

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.hsd1.ca.comcast.net)
Date: February 09, 2009 02:33AM

Yes I checked and double checked the syntax, and that's not it.

I installed wampserver on another machine and I have the same problems. I can tell that PHP and Apache work individually, but when I use the two scripts described above (form.html and action.php), the browser either asks me how to open the php file, or sends the entire text to the screen, depending on the browser (IE or Firefox).

When I run [localhost], I get the following:

Hi
Notice: Undefined index: name in C:\wamp\www\action.php on line 1
. You are
Notice: Undefined index: age in C:\wamp\www\action.php on line 2
0 years old.

So it looks like PHP by itself is working. Now when I run C:\wamp\www\form.html and I click submit, IE returns:

Hi <?php echo htmlspecialchars($_POST['name']); ?>.
You are <?php echo (int)$_POST['age']; ?> years old.

On the first machine where I installed wampserver, the browser says "It works!" in big bold letters when I type [localhost]. On the second machine the browser gives me a much more elaborate answer (logos, interactive menu where I can run phpinfo(), etc). Could this be a clue?

Thanks!

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: showstopper (---.rev.greendottt.net)
Date: February 09, 2009 03:08AM

make sure the lines are included in the httpd.conf file
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

Fitcom - Technology and SEO with a side of awesome

Installing and Configuring a WAMP Server in Windows 7 & 8

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.hsd1.ca.comcast.net)
Date: February 09, 2009 03:46AM

Yes these lines are included in the httpd.conf file.

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: xundy (---.dip.t-dialin.net)
Date: February 09, 2009 05:01PM

A pph files starts with <?php and not with any other characters or signs.

so it hast to be:

<?php
echo "Hi ".$_POST['name'])."<br />
You are ".$_POST['age']." years old";
?>

regards

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 09, 2009 05:46PM

no it doesnt, its fine to have

hi <?php

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.cisco.com)
Date: February 09, 2009 08:16PM

Apache is still not interpreting the php code, the various browsers are either dumping the php text to the screen or asking me how to open the php file. I've checked and tried the following things. What else could I look at?

Thanks!

PHP.ini
=======

1)
Changed from off to on:
short_open_tag = On
Didn't work

Php.ini exists in 3 locations:
c:\wamp\bin\php\php5.2.8
c:\Documents and Settings\all users\Start menu\Program\PHP 5 (as a shortcut)
c:\wamp\bin\apache\Apache2.2.11\bin

deleted the shortcut, rebooted but didn't work

httpd.conf
=========

1)
the line PHPIniDir "c:/wamp/bin/php/php5.2.8" was not in httpd.conf. I added the line after
DocumentRoot "c:/wamp/www/" , restarted the services but didn't work

2)
When my browser said "It Works!" after typing localhost it was finding c:\wamp\apache\apache2.2.11\htdocs\index.html
Add
DocumentRoot "c:/wamp/www/"
Now it finds the correct index.html

3)
OK LoadModule is here and it has forward slashes
LoadModule php5_module "c:/wamp/bin/php/php5.2.8/php5apache2_2.dll"

4)
I read somwhere that the line AddType application/x-httpd-php .php should be at the end, so I changed from:

<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3
</IfModule>

to:

<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php
</IfModule>

But that didn't work

5)
These warnings are in the php_error.log. Do they matter?

[09-Feb-2009 10:49:03] PHP Notice: Undefined variable: mywampfp in C:\wamp\scripts\refresh.php on line 252
[09-Feb-2009 10:49:03] PHP Notice: Undefined variable: i in C:\wamp\scripts\refresh.php on line 252
[09-Feb-2009 10:49:03] PHP Notice: Undefined variable: mywampini in C:\wamp\scripts\refresh.php on line 252
[09-Feb-2009 10:49:03] PHP Notice: Undefined offset: 1 in C:\wamp\scripts\refresh.php on line 385
[09-Feb-2009 10:49:03] PHP Notice: Undefined offset: 1 in C:\wamp\scripts\refresh.php on line 385
[09-Feb-2009 10:49:03] PHP Notice: Undefined variable: list in C:\wamp\scripts\wampserver.lib.php on line 33
[09-Feb-2009 10:49:03] PHP Warning: Invalid argument supplied for foreach() in C:\wamp\scripts\refresh.php on line 497

6)
OK the following is in the httpd.conf in the </Directory> section
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 09, 2009 10:27PM

did u try a different browser?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.cisco.com)
Date: February 09, 2009 10:29PM

Yes, IE and Mozilla. Didn't try Chrome.

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 09, 2009 10:37PM

so ur saying


<?php
phpinfo();
?>



in a file will work?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.cisco.com)
Date: February 09, 2009 10:53PM

Yes

I'm calling this through the localhost/info.php command

info.php:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

// Show just the module information.
// phpinfo(8) yields identical results.
//phpinfo(INFO_MODULES);

?>

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 09, 2009 10:56PM

ok so try
change the info.php file to this code



info.php
-------


<?php
echo 'hello';
?>

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: Phil3566 (---.cisco.com)
Date: February 10, 2009 01:09AM

It says:

hello

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: yfastud (Moderator)
Date: February 10, 2009 03:03AM

Quote

1)
the line PHPIniDir "c:/wamp/bin/php/php5.2.8" was not in httpd.conf. I added the line after
DocumentRoot "c:/wamp/www/" , restarted the services but didn't work
default does not have this line, wonder why you added it?

Quote

2)
When my browser said "It Works!" after typing localhost
when typing "localhost" and seeing "It Works!", most likely you have IIS; IIS and Apache/Wamp are both web server and might conflict in some way, so you have to disable IIS in order for Wamp to work

Disable IIS in Vista:

Control Panel, Uninstall Programs, Turn Widows Features On or Off, uncheck Internet Information Services

Disable IIS in XP:

Control Panel, Add/Remove Programs, Add/Remove Windows Components, uncheck Internet Information Services (IIS)

Restart computer, then restart Wamp

Also, open file hosts in folder C:\WINDOWS\System32\drivers\etc and make sure you have only this line and nothing else

127.0.0.1 localhost

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: browser opening php files instead of running them
Posted by: stevenmartin99 (---.b-ras1.blp.dublin.eircom.net)
Date: February 10, 2009 06:46AM

php is clearly working if it says hello

i honestly think its ur action.php file


try use ur info.php file with code from actoin.php and change the file in the form to rule this out

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote


Sorry, only registered users may post in this forum.