Re: [PHP] absolute vs relative path?

2006-01-28 Thread Jason Petersen
On 1/25/06, William Stokes [EMAIL PROTECTED] wrote:


 I Have a web site on one server and a test site on another. How can I
 build
 the hyperlinks so that they work on both servers without modification.


The cleanest solution is to use relative paths so that your site will work
regardless of where it's placed on the web server.  Sometimes it can be
tricky to determine what the relative path should be, but PHP can help solve
that.  Simply write a function or method to calculate the path to the base
directory of the site.  Make this a global variable and echo it before any
path to a resource on the site.

global $PATH;

echo a href=\{$PATH}images/blah.gif\ /\n;

Jason


[PHP] absolute vs relative path?

2006-01-25 Thread William Stokes
Hello,

I Have a web site on one server and a test site on another. How can I build 
the hyperlinks so that they work on both servers without modification.

For example build this link dynamically:
http://www.domain.com/www/test.php

In test server the same should be:
http://internalserver/www/test.php

Thanks
-Will 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] absolute vs relative path?

2006-01-25 Thread Jim Moseby
 Hello,
 
 I Have a web site on one server and a test site on another. 
 How can I build 
 the hyperlinks so that they work on both servers without modification.
 
 For example build this link dynamically:
 http://www.domain.com/www/test.php
 
 In test server the same should be:
 http://internalserver/www/test.php
 

Well, for hyperlinks to local pages, you can leave off the domain part all
together.  So in the above example you would just use /www/test.php.  Any
hyperlinks to remote servers would be the same in test as they are in
production.

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] absolute vs relative path?

2006-01-25 Thread Geoff
On 25 Jan 2006 at 15:19, William Stokes wrote:

 Hello,
 
 I Have a web site on one server and a test site on another. How can I build 
 the hyperlinks so that they work on both servers without modification.
 
 For example build this link dynamically:
 http://www.domain.com/www/test.php
 
 In test server the same should be:
 http://internalserver/www/test.php

Non-php solution:

Use relative links. Instead of referring to a page as 
http://www.domain.com/www/test.php;, rather just use 
/www/test.php or even just /test.php, if the script containing 
that link is already in /www. Thus your links will look the same on 
both versions.

php-based solution:

If you must have absolute URLs (maybe to do redirects or SSL) use:
$_SERVER[SERVER_NAME]
it will return either www.domain.com or internalserver. So you 
can build your links as:

?php
$url = 'http://' . $_SERVER[SERVER_NAME] . '/www/test.php';
?

Geoff.

 
 Thanks
 -Will 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] absolute vs relative path?

2006-01-25 Thread Barry

Geoff wrote:

On 25 Jan 2006 at 15:19, William Stokes wrote:



Hello,

I Have a web site on one server and a test site on another. How can I build 
the hyperlinks so that they work on both servers without modification.


For example build this link dynamically:
http://www.domain.com/www/test.php

In test server the same should be:
http://internalserver/www/test.php



Non-php solution:

Use relative links. Instead of referring to a page as 
http://www.domain.com/www/test.php;, rather just use 
/www/test.php or even just /test.php, if the script containing 
that link is already in /www. Thus your links will look the same on 
both versions.


/test.php would refer to root.
so it would be www.domain.com/test.php
not www.domain.com/www/test.php (!)

probably a small typo ;)

Barry

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] absolute vs relative path?

2006-01-25 Thread Geoff


On 25 Jan 2006 at 15:22, Barry wrote:

 Geoff wrote:
  On 25 Jan 2006 at 15:19, William Stokes wrote:
  
  
 Hello,
 
 I Have a web site on one server and a test site on another. How can I build 
 the hyperlinks so that they work on both servers without modification.
 
 For example build this link dynamically:
 http://www.domain.com/www/test.php
 
 In test server the same should be:
 http://internalserver/www/test.php
  
  
  Non-php solution:
  
  Use relative links. Instead of referring to a page as 
  http://www.domain.com/www/test.php;, rather just use 
  /www/test.php or even just /test.php, if the script containing 
  that link is already in /www. Thus your links will look the same on 
  both versions.
 
 /test.php would refer to root.
 so it would be www.domain.com/test.php
 not www.domain.com/www/test.php (!)
 
 probably a small typo ;)

Oops, twas indeed. Well spotted :-

 
 Barry
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] absolute vs relative path?

2006-01-25 Thread Richard Correia
I would suggest to keep a simple variable $HOSTNAME in your config file.

Thanks
Richard

On 1/25/06, William Stokes [EMAIL PROTECTED] wrote:

 Hello,

 I Have a web site on one server and a test site on another. How can I
 build
 the hyperlinks so that they work on both servers without modification.

 For example build this link dynamically:
 http://www.domain.com/www/test.php

 In test server the same should be:
 http://internalserver/www/test.php

 Thanks
 -Will