Jump to content

PHP Scripts layout


moosey_man1988
Go to solution Solved by ginerjm,

Recommended Posts

Hi Everyone i know this is a bit basic, but I have been working on a project and to tidy things up i have been placing them in directories.

 

my problem is I need to know how to plan this so i dont need to call an "include" or "require" in every page.

 

as it gets difficult when you are going back a directory and then into another directory for example:

 

in the html folder I have

 

index.php

 

sessions/login.php

 

functions/functions.php

 

index.php can all the functions via "include ('functions/functions.php');

 

but if we need the login.php to require functions it needs to be ('../functions/functions.php');

 

this can sometimes having something like a header.php in every page as it would call the script wrong directory.

 

would some be able to help so that i either don't need to include a script on every page, or maybe i can define functions that are a constant?

 

please let me now if this makes no sense! as ts a little difficult to explain.

 

Thanks in advance for any help given <3

Link to comment
Share on other sites

  • Solution

So you have a little module that defines paths

 

/*  paths.php

$php_path = "/home/domain/php/";

$lib_path = "/home/domain/public_html/libs/";

...

...

 

 

Then in your code you include the above file and in your other includes you use the appropriate path var:

 

include($php_path . "connect.php");

include($lib_path . "functions.php");

...

...

Link to comment
Share on other sites

For server includes is no need for the protocol, you can link to local files.

 

Additionally can link to css,images and such within the html using absolute url without a protocol

<img src="//mysite.com/image.png" />

 

Check out some server variables can use

 

A while ago I babbled on a bit about the differences in a post, take a look.

http://forums.phpfreaks.com/topic/292789-paths-when-rewriting-urls/?p=1498045

Edited by QuickOldCar
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.