Mike Solstice Posted January 3, 2010 Share Posted January 3, 2010 Ok, I'm just learning PHP and I'm stuck. Basically it's something like this: I own a website where clients can purchase "copies" of a php script I made, that is run on my own server with their own subdomain (of their choosing) that is automatically created by WHMCS using cPanel/WHM. Originally I was just putting a fully copy of the script in their public_html dir using WHM's skeleton directory, which works fine. The problem now is that there are a LOT of accounts, so upgrading & having to manually upload the upgrades to every cPanel user takes forever. So I'm trying to figure out how to save some time. The idea I had was to use basically dynamic content. I want to be able to only have an index.php and config.php file in the client's public_html directory and then pull header.php, content.php & footer.php dynamically creating the pages to display on their subdomain. I thought using: <?PHP include("http://example.com/header.php"); ?> <?PHP include("http://example.com/content.php"); ?> <?PHP include("http://example.com/footer.php"); ?> Would work, but that causes the server to look for the function.inc.php and config.php file on the "core" domain; I need it to pull the function.inc.php file from the core domain BUT get the config.php values from the requesting subdomain. Is it possible to make function.inc.php look include the config.php file from the requesting subdomain? Using Apache + MOD SSL and MySQL 5.1.30 Any & all help would be greatly appreciated...and please keep in mind that while I'm not exactly a newbie, I am still new to all of this....so detailed replies (with examples if at all possible) would be very, very much appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/ Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 Just place the files in one central location and include them from there using an absolute path. Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987581 Share on other sites More sharing options...
Mike Solstice Posted January 3, 2010 Author Share Posted January 3, 2010 Thank you for your reply. Could you maybe expand on that a bit? I don't know what you mean by "absolute path" - the server path? the url? As far as placing them in a central location, that is the general idea with the exception of the index.php and config.php & is the exact problem. Let me clarify... Clients domain is, let say http://client.example.com Central Location is http://core.example.com http://client.example.com/index.php would include http://core.example.com/header.php http://core.example.com/content.php http://core.example.com/footer.php http://core.example.com/header.php has a php include to call http://core.example.com/function.inc.php which in turn needs to call http://client.example.com/config.php to get their sql db credentials, connect to their database, pull the data & form http://core.example.com/content.php. I need the pages to be built using files from http://core.example.com but have http://core.example.com/function.inc.php include http://client.example.com/config.php & http://client.example.com needs to be automatically detected as the subdomain that is calling the files from core.* EDIT: I googled absolute path & figured out what you mean, the server's absolute path. I don't think that will work. As I said, the subdomain needs to be automatically detected & I'm using cPanel/WHM which creates an account for every user & their own public_html directory. So if absolute paths were used, then I would need a way to automatically detect the username that belongs to the subdomain - and thus still have the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987582 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 Urls and domains have nothing to do with it. Place the files you want to include in a central location like /usr/share/php then simply include them from wherever using.... include '/usr/share/php/foo.inc.php'; I assume this is a dedicated box or at very least a vps? Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987585 Share on other sites More sharing options...
Mike Solstice Posted January 3, 2010 Author Share Posted January 3, 2010 Ahh ic. No, it's a shared reseller server so I'd assume this would be more of an issue of cross-domain scripting? All the domains are at least on the same box though. So could I do like /usr/home/my_username/php/file.to.include.php? Would I stll use just include 'config.php'; in the function.inc.php that would be called from the central dir? Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987586 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 So could I do like /usr/home/my_username/php/file.to.include.php? Yes. Would I stll use just include 'config.php'; in the function.inc.php that would be called from the central dir? No. You would need to use an absolute path there as well because it will look for the file in relation to the calling file otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987588 Share on other sites More sharing options...
Mike Solstice Posted January 3, 2010 Author Share Posted January 3, 2010 That worked!! YOU ROCK!! THANK YOU THANK YOU THANK YOU!! omg...I spent like 5 hours Googling for that answer & got absolutely nada. Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987592 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2010 Share Posted January 3, 2010 Edit: A slightly different angle - your main file should include things it needs to make up the application. A function.ini.php file should contain functions only. A config.php file should contain config information only and the function file should not be responsible for including the config file. but have http://core.example.com/function.inc.php include http://client.example.com/config.php Nope. That implies that you have not written the functions to be general purpose. It should not matter WHERE you include functions from, they should be able to use the existing config information that was included by the main file. Main file: index.php (specific to each client/subdomain) - <?php include config.php; // include specific config information include $absolute_file_path_to_core_files . "/function.inc.php"; include $absolute_file_path_to_core_files . "/header.php"; include $absolute_file_path_to_core_files . "/content.php"; include $absolute_file_path_to_core_files . "/footer.php"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987594 Share on other sites More sharing options...
Mike Solstice Posted January 3, 2010 Author Share Posted January 3, 2010 Nope. That implies that you have not written the functions to be general purpose. It should not matter WHERE you include functions from, they should be able to use the existing config information that was included by the main file. The functions are the same across the whole system, regardless of the client. The problem I had run into was that b/c I was using core.example.com to include the files and not the absolute path it was causing it to look only at core.example.com when it needed to look for the config.php at client.example.com if that makes any sense lol Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987598 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 Including files via http (eg a url) doesn't actually include any functions or variables into the same scope, only there output. Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987603 Share on other sites More sharing options...
Mike Solstice Posted January 3, 2010 Author Share Posted January 3, 2010 ahhh ic ic...makes sense & totally not something I would have thought of (but hey, I'm learning lol) So then I'd assume that doing this cross-domain, on completely unrelated boxes, would not be possible? Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987606 Share on other sites More sharing options...
trq Posted January 3, 2010 Share Posted January 3, 2010 So then I'd assume that doing this cross-domain, on completely unrelated boxes, would not be possible? Not without network mounting the relevant drives so they appear to be local. Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987609 Share on other sites More sharing options...
Mike Solstice Posted January 3, 2010 Author Share Posted January 3, 2010 Good to know. Thanks again! Really really appreciate the help! Quote Link to comment https://forums.phpfreaks.com/topic/187008-dynamic-content/#findComment-987611 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.