first php pages on wamp server... having issues...

seems like I’m having some issues understanding this (and getting it to work properly)… i found this article: http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL and tried to follow what was going on…

i created the pages as detailed, found some errors and fixed them (on last page of comments)

im trying to create a test web page where users wiil:

  1. log in/get verified
  2. allow some users to edit a mysql database on cars bought and sold at auctions
  3. allow all users to see the mysql database records so they can review them…

now,this is NOT working right for me. First shot at programming php,mysql,java,html,etc. I’m really in the dark…

my first questions are,

all these .php files will go in the www folder?

when should/ do i make sub folders in the www folder?

(trying to understand php directory structure from the web page point of view)

any help appreciated. thanks

Well from the browser’s point of view (the finished webpage), it never sees any PHP. All of that is done server side.

Now since the server is responsible for processing the PHP files, you have to ensure that you’ve correctly configured your web server, whatever software program that is (Apache, nginx, Lighttpd, IIS, etc.) to recognize and process the PHP code you put into your HTML markup (the PHP files). These usually go into your server’s document root (you can find out what and where this is by reading the documentation that goes with your server (for Apache, this is usually /var/www on Linux and /htdocs on Windows)).

Since your shooting in the dark here and it seems you are new at this, I would advise you to read slowly and carefully so as not to rush over key pieces of information. God knows I did and spend many a night pulling my hair and developing bloodshot eyes.

Answer to question one yes all .php files have to go into the www. folder.
Answer to question two I always put all my .php files in sub folders , one of the reasons for that is when you go to the task bar and click on the Wamp logo and you go to localhost if you do not put your .php files in a folder they will not show up and I find it helpful to be able to go to localhost click on my folder and then open my PHP files. Hope this helps

“I always put all my .php files in sub folders , one of the reasons for that is when you go to the task bar and click on the Wamp logo and you go to localhost if you do not put your .php files in a folder they will not show up and I find it helpful to be able to go to localhost click on my folder and then open my PHP files. Hope this helps”

I am running a wamp server,(all works as its supposed to so far) so all the files are in the www folder.

question… when i specify a .php file in a html(php) page, and that .php file is in a sub folder of www, how does php find that .php file in the sub folder? is some kind of indexing required? not sure how the “configurement” of the folder structure effects php running those files???

i saw this basic lesson… “You are probably very familiar with the public_html structure. This is the Document Root in which all your public files are accessed (/public_html/page.php is accessed at example.com/page.php).
img — All your image files. I decided to split content images from layout images.
css — All your css files.
js — All your javascript files.
The resources directory should hold all 3rd party libraries, custom libraries, configs and any other code that acts as a resource in your project.
config.php — Main configuration file. Should store site wide settings.
library — Central location for all custom and third party libraries.
templates — Reusable components that make up your layout.” from http://net.tutsplus.com/tutorials/php/organize-your-next-php-project-the-right-way/

this seems logical to me, I’m just at a loss understanding how the html page will direct a php code “reference” to the proper .php file it needs… I’m thinking i need to define paths to the proper .php files?

any thoughts appreciated…thanks for the answers!

PHP just uses the path specified in your include or require method; much like you typing a path to a file in Windows Explorer’s (the file browser you use to look through your documents) URI bar at the top and hitting return (enter).

Ok, now I think I understand what you were asking across the entire post. The above isn’t necessarily applicable yet in your question.

In order for you to understand how the web page will, as you put it, “direct a php code reference”, also known as a HTTP Request, you need to understand what an URL (Uniform Resource Locator) does.

The web server itself handles all the HTTP Requests made to access your files. So for example, if someone visits a website with the URL http://www.example.com/index.php, the web server will receive the request and translate that into a URI (Uniform Resource Indicator) that’s used by the web server’s host OS. So http://www.example.com/index.php basically becomes /index.php. The newly created URI is basically a file path, relative to the web server’s document root.

Since you are using WAMP (Windows Apache MySQL PHP), and I am assuming that you have a default configuration (you haven’t changed any of the configuration files such as httpd.conf or php.ini), Apache (the web server) will use the URI (/index.php) to load the requested web page (also known as a Resource, as in URL and URI). If the index.php file is present at / (the document root), then Apache loads the file and hands over control to PHP which processes any PHP code and then sends out the results to the client’s browser.

So, in other words, every time you type in a link while coding your web pages, all you have to worry about is that your path is correct and the web page (.php, .html, .js, or .css file resource) your linking to exists. If they don’t, you get Error 404 (Resource not found).

wow. thanks, thats a lot. You got my question exactly. i understand http is the “protocol,” using port 80 on my server.
and https is basically the same protocol, except a different port, and “security and encryption” and “authentication”

first problem… I’m not understanding how the “http” request the user submits would know whether to display.php or html? or they are both the same thing just a different computer “language”… .php or html

.jss (java) (i believe java makes your pc do something, i.e. start a download?)

.css as i understand changes the “way the page looks to the client?”

so in a .php page it can have a php function, a css function, a html coding? and the .php code is calling up .css and .html “coding” on the server folders (www) to return that info into the users/clients browser so the web page looks ok?

Since you are using WAMP (Windows Apache MySQL PHP), YES

and I am assuming that you have a default configuration YES (you haven’t changed any of the configuration files such as httpd.conf or php.ini), I HAVE NOT CHANGED ANYTHING

Apache (the web server) will use the URI (/index.php) to load the requested web page (also known as a Resource, as in URL and URI). If the index.php file is present at / (the document root), www folder at c:\wamp\www?

then Apache loads the file and hands over control to PHP which processes any PHP code and then sends out the results to the client’s browser. www/index.php???

So, in other words, every time you type in a link while coding your web pages, all you have to worry about is that your path is correct and the web page (.php, .html, .js, or .css file resource) your linking to exists. If they don’t, you get Error 404 (Resource not found). this is all in the config file?

thanks for all the help…

Nonsense! :o

PHP files can reside anywhere you like! Infact, for security reasons, some php files should NEVER be in the public folder!

My advice to the original poster, create a directory structure that both works and you’re comfortable with - IE: you know what files are where - and why you put them there in the first place.

After building a few sites with lots of ‘included’ pages, you’ll soon see the benefit of having certain files go in certain places because they are easier to maintain in the long run.

Just my two-pence worth.
Red :wink:

Edit: This is a pretty logical way to do things :wink:

No need for caps text ::), I wince all the time when I read that! I usually ask these questions since the whole point is to get the easy stuff out of the way.

I probably should have paid more attention to the specific software package that you use called “WAMP” as opposed to the general acronym WAMP (Windows Apache MySQL PHP). The reason being I use “XAMPP” for development, which as I have re-read your posts, has a different directory structure than “WAMP”, even though both are technically WAMPs.

Now onwards to reaffirm your answers.

Correct. ;D That’s the Document Root. (For me its /htdocs, which is also Apache’s default).

The file being index.php loaded from the Document Root ( which is the / in the url after the domain name; likely in your case to be localhost) by the URL http://localhost/index.php.

EDIT:

(SOURCE: How To Optimize Your Site Using GZip Compression)
This image should help explain the question above a little better…
END EDIT

No no no, you’re typing to create ( i.e., code) HTML, CSS, PHP, or JavaScript in this case. The web server software (Apache) takes care of handling your users (clients) and delivering the code you’ve typed to them.

The important thing to take away here is that the configuration files (httpd.conf) change the default behavior of how the web server software handles your client’s requests to the server. An example which would require changing the configuration files, utilizing my previous description, would be the server returning a response of Error 404 - Not Found. You can specifiy your own (more user friendly) error documents to deliver instead of having the web server (Apache) generating its own (minimal) error document on the fly.

2[sup]nd[/sup] EDIT:This tutorial should help explain things MUCH better :smiley:
http://coredogs.com/lesson/how-php-pages-run

Sponsor our Newsletter | Privacy Policy | Terms of Service