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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.