Calling table from external database/cms install

8 posts by 4 authors in: Forums > CMS Builder
Last Post: April 23, 2010   (RSS)

Re: [rjbathgate] Calling table from external database/cms install

By Dave - June 11, 2009

Hi Rob,

It doesn't really work like that. Would it work to just include a remote file from the other server? That might be simpler. If you have the site with the html output it as an include you do one of the following:

- include it in an iframe

- include it with a javascript tag (need to add document.write and escape content)

- use this PHP snippet to load the page (the getPage function gets loaded with CMS Builder):
<?php
list($html, $httpStatusCode) = getPage("http://www.interactivetools.com/includes/header.html");
print $html;
?>

Would any of those work? These are also good ways to "syndicate" content when you have a client who has a page or snippet they want to allow others to add to their sites.

Let me know if one of those would work, otherwise we can try something else.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Calling table from external database/cms install

By rjbathgate - June 11, 2009

Hey,

Thanks - used getPage -- had to tweak a few things to compensate for page being external, but got there in the end, cheers!

Rob

Re: [rjbathgate] Calling table from external database/cms install

By kdub718 - April 13, 2010

I'm trying to do this same thing...

I just can't get it to work. Can you maybe explain how you used the getPage function? Do you have to replace the require_once?

Lets say I have siteA and siteB...

I want siteA to have the mysql database and then have siteB pull the same (for example) newspage as siteA.

Re: [kdub718] Calling table from external database/cms install

Ok,

You need a php page displaying the news articles form your sql, so on siteA.

Say: www.sitea.com/news-for-siteb.php

This file renders the news as required as you would if it was a news page for siteA. Completely normal.

Then on siteB you have www.siteb.com/news-from-sitea.php, and within it, where you want the news to display, the code:

<?php
list($html, $httpStatusCode) = getPage("http://www.sitea.com/news-for-siteb.php");
print $html;
?>


So this essentially displays the contents of news-for-siteb.php from SiteA (rendered by siteA).

Your require_once stuff is on www.sitea.com/news-for-siteb.php as if it were a normal news page for siteA.

For styling, I would recommend having www.sitea.com/news-for-siteb.php include your layout requirement (<divs> etc), with siteB having the css for said <divs>

Hope this helps

Re: [rjbathgate] Calling table from external database/cms install

By Chris - April 14, 2010

Hi there,

Just a note: many hosts will allow you to host multiple web sites (e.g. www.sitea.com and www.siteb.com) both from the same server. This configuration may simplify things greatly. :)
All the best,
Chris

Re: [chris] Calling table from external database/cms install

By kdub718 - April 16, 2010 - edited: April 16, 2010

But I think both domain names would have to be on that server aswell. Which in this case they are not.

I mean you can forward but then essentially your leaving that domain and if people bookmark its kinda dumb. Among many other reasons...

Then blind forward will always take you back to index page if you refresh or anything like that.

maybe I'm wrong and there is another way...?

Re: [kdub718] Calling table from external database/cms install

By Dave - April 23, 2010

>maybe I'm wrong and there is another way...?

You can do a redirect with mod_rewrite like this that will maintain the path from root and the query string, etc:

# Redirect to new domain
RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [L,QSA]

http://www.siteA.com/dir/file.php?name=value#link redirects to:
http://www.example.com/dir/file.php?name=value#link

Or if you have mod_rewrite and mod_proxy you can do this:

RewriteEngine on
RewriteRule ^(.*)$ http://www.example.com/$1 [P,QSA,L]

http://www.siteA.com/dir/file.php?name=value#link loads the content from
http://www.example.com/dir/file.php?name=value#link

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com