browsers download php file instead of running it
Posted by: laxwamp (---.static.youbroadband.in)
Date: September 27, 2012 01:31PM

I'm running a piece of php code (servertime.php placed in RD folder of www and accessed it localhost/RD/servertime.php

Code below:

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
//echo "data: The server time is: {6}\n\n";
echo(rand(10,100));

flush();
?>

IT IS JUST RUNNING THE FILE "file:///C:/Users/lakshmanan.palani/Downloads/servertime%20(22).php" this may be due to I have asked to open it in Chrome while it is getting downloaded..


Gone through various forums and I have tried following things, but still it doesnt work


Try 1: configuring httpd.conf (failed)

---------------------------------

AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php5 (initially it is php3 changed to php5)

Added.........


AddHandler application/x-httpd-php .php .phtml


Try 2: WampManage menu

---------------------------------

PHP > PHP Settings > allow URL include
(via menu tried to enable it , but some error message thrown, but now showing with tick mark in the menu


Thanks for the Advance help.

Lax.

Options: ReplyQuote
Re: browsers download php file instead of running it
Posted by: RiggsFolly (---.as13285.net)
Date: September 27, 2012 01:46PM

Not quite sure what you are trying to do here !!!!

Maybe test a piece of code that will be called via AJAX ???


If you are getting the "file:///C:/Users/lakshmanan.palani/Downloads/servertime%20(22).php" then you are probably clicking on a file using explorer. THIS IS NOT THE WAY.

Open your browser, keyin

[localhost]

This is how you run a web page via the Apache server and PHP interpreter. Not by clicking on your file in explorer.


Additionally, undo all the changes you say you made to the configs, they are not necessary for the code you give as an example.

Also remove all the header() stuff and flush() they are also not required.

Options: ReplyQuote
Re: browsers download php file instead of running it
Posted by: laxwamp (115.241.59.---)
Date: September 27, 2012 08:34PM

@Riggs, thanks.

Actually the above code is called by a Server side event source. on the way of an analysis...

No i haven't directly clicked the file gone through localhost only, but still it is trying to download the file instead of executing it....

Mostly it is of some Wamp (apache ) config issue.... I think..

Options: ReplyQuote
Re: browsers download php file instead of running it
Posted by: stevenmartin99 (Moderator)
Date: September 27, 2012 09:47PM

You have the valid echo commented out!!!

Your second echo line is not valid for a server sent event because it does not start with "data:"


Use AJAX, honestly smiling smiley

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

Options: ReplyQuote
Re: browsers download php file instead of running it
Posted by: laxwamp (---.static.youbroadband.in)
Date: September 28, 2012 12:47PM

Yeah I got to know and thanks for making it to recognize further.. Not knowing this mistake I have browsed for solutions to config wamp for about 2 hrs! Thanks Steven..

Options: ReplyQuote


Sorry, only registered users may post in this forum.