Jump to content

totaly basic problem/first time using php


nzorb

Recommended Posts

Ok first of all I want to apologize for asking what I'm about to ask. I understand it should be some stupidly easy to find mistake but considering the fact I have to send the code tomorrow leaves me with little to no time to try and find the solution so I'll be asking here and hope that by the time I wake up tomorrow an answer will be here and I'll be able to resume scripting.

 

So my problem is that I just can't find how to make php commands run at all. I tried just randomly inserting them into my html code then found out it needs a separate file. So I created the basic.php with this code:

<html>

<body>

 

<?php

echo "Hello World";

?>

<div>adgaeganerhaohn</div>

 

</body>

</html>

tried opening it through a form in my html code but it wouldn't print the Hello world line, then I tried running it straight into firefox but I only got adgaeganerhaohn again (without that line I get a white page) So I need to know what am I doing wrong?

 

I have php5.301 installed with default options (no server).

 

thanks for your help beforehand, once I get a bit more into php I'll be coming back with serious questions but for now I really need someone to tell me how php is supposed to work and what I'm doing wrong :(

Link to comment
Share on other sites

You HAVE to have a webserver installed. If you try to open a file with PHP code in it directly in your web browser it has no clue how to parse PHP code. So, it just triesd to renders it all as HTML. You have to request the page from a web server. THe server then sees you want a PHP page. It takes the page and processes it then sends the result (HTML code) to your browser.

 

Once you have a webserver installed (check out XAMPP) you can put the php files into the htdocs folder on your PC. Then you could access them via http://localhost/filename.php

Link to comment
Share on other sites

...you can use a localhost to do this which is free

 

Your use of terminology will cause confusion. A "localhost" is not a webserver. Every machine has a "localhost" it is simply an internal domain name pointing the machine back to itself. When you use localhost in the URL you are simply making an http (usually) request back to the pc itself. It is no different than using the machines name or IP address. For example you can ping a cmputer back to itself using localhost even if it has no web server installed. And, you can have a webserver (which uses localhost) which is not free.

Link to comment
Share on other sites

wow tnx for the fast replies all! So all I have to do is set up a server with php support and throw the files there (even if 'there' is just my pc), sounds like a stupidly hard way to run a simple site but I guess there's a logical explanation behind it that I'll understand at some point :P tnx again I think this thread should be considered solved!

Link to comment
Share on other sites

...you can use a localhost to do this which is free

 

Your use of terminology will cause confusion. A "localhost" is not a webserver. Every machine has a "localhost" it is simply an internal domain name pointing the machine back to itself. When you use localhost in the URL you are simply making an http (usually) request back to the pc itself. It is no different than using the machines name or IP address. For example you can ping a cmputer back to itself using localhost even if it has no web server installed. And, you can have a webserver (which uses localhost) which is not free.

yes sorry if my wording caused confusion...thanks for clearing that up mjd

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.