PDA

View Full Version : Tweaking for Speed, Security and Other good stuff


Jazzylee77
January 26th, 2008, 03:31 PM
I'm one of those guys who, when it comes to any coding, I learn just what I need to make my current thing work and move on. So, obviously there all kinds of gaps in my knowledge. Or sometimes I know something is preferred, but since I don't know why it is preferred, I may not bother with it.

For Example: Paths and includes

I think I first learned to distinguish between absolute and relative paths when I installed my first amazon store about 3 years ago. For some reason the full path was necessary for something on my install. So putting the http://www.mysite.com/whatever in front of the /folder/file.php for

<?php include("http://www.mysite.com/whatever/folder/file.php"); ?> made it work.

This limited understanding got me into a little trouble. I didn't fully understand (and I'm sure I still don't) the different kinds of paths. It seemed sometimes a leading slash would make it work and other times not...if all failed I just put the full url in there to make it work.

Now I know that on a page located in http://www.mysite.com/whatever/folder/ <?php include("/file.php"); ?> includes a file from the top level folder.

and

<?php include("file.php"); ?> includes a file from the current folder http://www.mysite.com/whatever/folder/file.php

So why worry about it? If it works it works. Well it's not just a matter of a few less characters. (I may not get the technical explanation exactly right here) Using relative urls, is much faster. It keeps the request within the php interpreter. (I think) But to process a full URL it has to go to apache to be figured out, putting more load on the server.

So I'm wondering. I bet there are a lot of other things that are overlooked like that. What are some of the most common mistakes code mangler's like me make?

theking
January 26th, 2008, 10:43 PM
If you use the code

<?php include("http://www.mysite.com/whatever/folder/file.php"); ?>

the server has to call out to itself, provide the page, download the page provided, and part the raw text provided. It doesn't include any PHP code in the file.

HTTP urls and relative directory paths are two entirely different things. ;)