Re: PHP Template Trouble

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brad, I cant thank you enough!!! This has been getting to me for weeks.

I simply moved the mapping of the URL's so that all the URL's point to the same website, i could then use that http _host to pick them up and then i've basically used this to query the database and give me what I want. It was so simple in the end but I never even thought about doing it this way, i knew there would be an easy solution though.

It works perfectly, finally i can get some sleep.. now just got to get around to fixing all the installation!

Well, I'm sure there is a better way to do it, but this should work.

config.php does not need to be dynamic in this scenario.
1. Copy index.php and config.php into each site's directory.
2. Change the $db_name variable in config.php to use the correct database.

<?php
// c:\inetpub\www\example1\config.php
$db_host = "localhost";
$db_user = "foo";
$db_pass = "bar";

$db_name = "example1";
?>

<?php
// c:\inetpub\www\solution\config.php
$db_host = "localhost";
$db_user = "foo";
$db_pass = "bar";

$db_name = "solution";
?>

<?php
// index.php (gets copied into each directory)

include("config.php");
print "<html><head><title>".$_SERVER['HTTP_HOST']."</title><head><body>";
print "This site is using the database name \"{$db_name}\"";
print "</body></html>";

?>

If you can't get it to work using this method, I give up :P

Cheers ;)

- Brad


-----Original Message-----
From: Kevin [mailto:Kevin@xxxxxxxxxxxxxxxxx]
Sent: Thursday, October 26, 2006 10:39 AM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  PHP Template Trouble

But the dedicated server has security. In order to use it you must
create accounts (these are your ftp accounts) so basically I have

example mapped to www.example.com

and

example2 mapped to www.example2.com

example's root dir would be along the lines of:
c:\inetpub\www\example\htdocs

example2's root dir would be c:\inetput\www\example2\htdocs

Example2 cannot access the root dir of example because of the security,
it gives a permission denied error and the same the other way around.

Kevin

Brad Fuller wrote:
Cool, then what you want to do is make all the domains point to the same
directory, have your files index.php and config.php in that directory
and it
should work like magic.

Then you end up with one copy of the files and how ever many sites you
need.
No frames, no duplicated code.

It's been a long time (5+ years) since I worked with Windows/IIS, sorry
I
don't have more specific instructions on how to do the above.

Hope that's enough to get you started in the right direction.

-Brad


-----Original Message-----
From: Kevin [mailto:Kevin@xxxxxxxxxxxxxxxxx]
Sent: Thursday, October 26, 2006 10:15 AM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  PHP Template Trouble

Yes all the sites are located on a Windows 2003 Dedicated Server.

Kevin



Brad Fuller wrote:

Kevin,

Are all these sites hosted on the same box?

-Brad



-----Original Message-----
From: Kevin [mailto:Kevin@xxxxxxxxxxxxxxxxx]
Sent: Thursday, October 26, 2006 9:37 AM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  PHP Template Trouble

Hi Brad,

That sounds like a good idea however:

Where would config.php go? If it goes on the www.solution.com side of
things, then $_SERVER[HTTP_HOST] will always be www.solution.com and if
it goes on another then it would be www.example1.com.

What you have put would be the kind of solution I am looking for but
its
the $_SERVER[HTTP_HOST] variable that would need to be posted through
correctly, even if using frames on www.example1.com (using them to load
www.solution.com) $_SERVER[HTTP_HOST] would still equal
www.example1.com
Thanks

Kevin

Brad Fuller wrote:


Hi,

I am trying to have 1 template site and have an unlimited number of
websites using this template site to call there own information.

The sites are exactly the same except for the database, each of the
sites also needs there own URL, for example one of these urls may be
www.example1.com and the other www.example2.com. These sites are
identical apart from the database they call to, one will call to a
database called example1 and the other example2. I want another site
(for example www.solution.com) to read what url has been entered and
to pull in the database for that site (either example1 or example2)
and show that information. I have tried using the CURL library
without success (not sure how to use it fully) and have tried using
frames but had loads of problems regarding losing session data. can
anyone help?

Thanks
Kev




Here's just an idea to give you maybe a starting point to go from...

<?php
// config.php

$db_host = "localhost";
$db_user = "foo";
$db_pass = "bar";

switch($_SERVER["HTTP_HOST"]){
	case "www.example1.com":
		$db_name = "example1";
		break;
	Case "www.example2.com":
		$db_name = "example2";
		break;
	case "www.template.com":
		$db_name = "template";
		break;
}
?>

<?php
// index.php

include("config.php");

$link = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name);

...

?>



--
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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux