PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
devinmcmanus
Forum Newbie
Posts: 5 Joined: Mon Aug 27, 2007 6:29 pm
Post
by devinmcmanus » Mon Aug 27, 2007 6:49 pm
Hi I have a PHP site that currently has a production environment only. I am thinking about adding a staging environment. Here's a sample piece of code:
Code: Select all
<?php
$siteRoot = "http://www.myhost.com/mysite";
?>
<html>
<body>
<img src="<?php echo $siteRoot; ?>/_img/misc/myimage.jpg" />
</body>
</html>
What I would like to do is modify $siteRoot to be dynamic. In other words, I would like to be able to to have $siteRoot automatically detect where it is so that I can develop my site on
http://www.myhost.com/stage/mysite/ or
http://stage.myhost.com/mysite and deploy the live site to
http://www.myhost.com/mysite . Is there any way this can be done?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 27, 2007 6:55 pm
Look at details in $_SERVER.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 27, 2007 7:05 pm
Most often you don't need to use full URLs for internal links unless they are across subdomains.
devinmcmanus
Forum Newbie
Posts: 5 Joined: Mon Aug 27, 2007 6:29 pm
Post
by devinmcmanus » Mon Aug 27, 2007 7:18 pm
So basically you're saying I should switch everything to use relative paths?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 27, 2007 7:36 pm
You can still use absolute paths, but the protocol, domain and port are not required when they are the same as the current URL.
devinmcmanus
Forum Newbie
Posts: 5 Joined: Mon Aug 27, 2007 6:29 pm
Post
by devinmcmanus » Mon Aug 27, 2007 7:43 pm
Can you give an example please?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Aug 27, 2007 7:45 pm
They would look like any other absolute path for an operating system (without a drive letter if you're on Windows.)