Jump to content

Dynamic Content


Mike Solstice

Recommended Posts

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!

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

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";
?>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.