Forum Moderators: coopster

Message Too Old, No Replies

Link depth question

         

bobnew32

10:24 pm on Nov 14, 2004 (gmt 0)

10+ Year Member



Any good coding that a person does should be able to be used on multiple amounts of domains. Mine currently is not! It is only able to be used on one domain, and I currently can't run the code from my own computer to test things out due to include links pointing to files that would change under different systems.

My question is, how do you guys handle this? I'm pretty sure you "define" the absolute link to a users "home" location, and go from there I guess? Where do you store this defined variable at, the index page?

I'm curious to hear what you users do with this situation that occurs everytime you code.

Deab

11:07 pm on Nov 14, 2004 (gmt 0)

10+ Year Member



All our links are relative (ie product/23/prod_name).

I run the same site in 3 different locations 'dev' on a vmware server at home, 'live' and 'test' are on the hosted server. 'Test' runs under a sub directory of the live site.

I have a url() function that I pass all url's through, so if I need to make a change its only in one place.

bobnew32

11:31 pm on Nov 14, 2004 (gmt 0)

10+ Year Member



Yes but the problem is I have some links that in a library folder that are outside of public_html so that they can't be read. Mainly I care more about including the right library files and etc rather than creating the right links.

bobnew32

3:56 am on Nov 15, 2004 (gmt 0)

10+ Year Member



Hmmm deab could you give me an example of using your url() function?

Deab

8:17 am on Nov 15, 2004 (gmt 0)

10+ Year Member



URL() function below.

Usage example:


$linksurl=url('links');

IsTest() is a function that returns TRUE if the page is running on the Test server (as it runs in a sub-directory of Live, there are some exceptions to deal with).

$_SESSION['homedir'] contains the directory name if any (on Dev server, its the project name, on Test, its 'dev').


function url($url='')
{ // check for 'photos' or 'images', convert to absolute url if found
if (IsTest())
{
if (substr($url,0,7)=='images/' ¦¦ substr($url,0,7)=='photos/')
return('http://www.MYSITEURL./'.$url);
}
return($_SESSION['homedir'].$url);
}

mincklerstraat

9:39 am on Nov 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To get to something that's in the directory right under webroot, if the page/file calling it is in webroot is:
include '../filename.php';

if it's in a directory that's in the directory right under webroot it's:
include '../directoryname/filename.php';

I consistently just use relative url's like this.

coopster

11:35 am on Nov 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at the Control your included files (message # 17) in the latest Bag 'o Tricks [webmasterworld.com] thread.

And Welcome to WebmasterWorld there, Deab.

bobnew32

4:23 am on Nov 16, 2004 (gmt 0)

10+ Year Member



Question, what are the differences between these? Say i'm running these lines of codes on index.php:

include '../public_html/imap.php';
include './imap.php';
include '/imap.php';


(imap.php is located in the public_html folder)

coopster

12:45 pm on Nov 16, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



/  - the root directory 
. - current directory
.. - parent of current directory