localhost/ remote confusement.

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

localhost/ remote confusement.

Post by redhair »

Code: Select all

<?php

if (!$home_url)
{
$host = getenv("HTTP_HOST");

	if ($host == "localhost")
	  {$home_url = "http://$host/mysitelocal/";}
                else 
	  {$home_url = $host;}
	  session_register(home_url);
}

?>
Before I used this code, I found myself confused on a number of occasions when editting my css for example (changing something and nothing happens....I'm sure I'm not alone on this one;)

See how I call my css these days.

Code: Select all

&lt;link rel='stylesheet' type='text/css' href='&lt;? print "$home_url"; ?&gt;css/styles.css'&gt;
Now when I test my site local, it uses the local css, and when i putt the script on the remote server, it uses the remote css.

I also use it for images and stuff.
User avatar
uberpolak
Forum Contributor
Posts: 261
Joined: Thu Jan 02, 2003 10:37 am
Location: Next to the bar

Post by uberpolak »

Why not just use relative paths?
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

uberpolak wrote:Why not just use relative paths?
Because my header.inc (..4 example) must work in deeper directory structures.
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post by mchaggis »

so why not use relation for root?

ie:

Code: Select all

<link href="/css/layout.css" rel="stylesheet" type="text/css" />
That way it doesn't matter at all where you are in the site
Post Reply