Jump to content

[SOLVED] Newbie Question


ocanyc

Recommended Posts

So I finally setup an apache server, with php and mysql on windows. This is for fun and learning btw. I'd like to get into php programming now. I was following some tutorial where it had me write a simple script. Just a display in the browser. Here is my question because at first it didnt work, when I opened the php file from the browser. I'm hoping this is a simple question for you guys using apache servers.

 

Basically this works.....

http://localhost/easy_script.php

And I get the display I'm suppose to see:

 

Agent: So who do you think you are, anyhow?

Neo: I am Neo, but my people call me The One.

 

This doesnt:

file:///C:/Public_Html/Easy_Script.php

I only get this part:

Agent: So who do you think you are, anyhow?

 

 

Here is the script code:

 

<html>

<head></head>

<body>

 

Agent: So who do you think you are, anyhow?

<br />

 

<?php

// print output

echo 'Neo: I am Neo, but my people call me The One.';

?>

 

</body>

</html>

 

 

 

My main question is, why does php work when I open it using my localhost address. But when opened as a file in the browser it doesnt. Is there something I should check in the php.ini file, or the Apache httpd.conf file? Seems it should work both ways?Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/59210-solved-newbie-question/
Share on other sites

This is completely normal. Accessing the file via http://localhost means that your apache server serves the request, hence your php is executed. Simply opening the file via file:// does not execute the php.

 

PHP is executed at the server. This is the entire reason you installed a server in the first place.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.