processs php commands embedded in database table

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
TonyBunney
Forum Newbie
Posts: 7
Joined: Thu Jul 30, 2009 8:26 am

processs php commands embedded in database table

Post by TonyBunney »

I have a number of web sites which share information and after looking at using include to utilise common files/data I found that there maybe security issues with this and my hosting service has allow_url_include set to false (0).
All of my websites are hosted on the same host and therefore can share the database which I have set up, so I migrated a lot of the shared logic to ustilise information from the database which is working well but in addition to data on the database which controls what the sites show etc, I also want to use shared pages from the database. The problem I am having is that the data retrieved from the database is not processed by php.
An example of what I am trying to is a simple contact page.
contact.php would contain the following:- (note error processing removed)
echo '<!DOCTYPE html PUBLIC .......
$SiteURL = ($_SERVER['SERVER_NAME']);
$DBConn = mysql_connect(localhost,$WSDBU,$WSDBP);
$db_selected = mysql_select_db($WSDB, $DBConn);
$DBResult = mysql_query("SELECT PageContents FROM Pages");
$num=mysql_numrows($DBResult);
echo $DBResult; blah blah

$DBResult, i.e. the data retrieved from the database contains the following piece of code <p> Please visit our site at <?php echo $SiteURL; ?></p>

But instead of displaying the contents of $SiteURL the page displays the actual php code.
Please tell me if what I am treying to do is possible.
I have only been programming with PHP and MYSQL for a few months now and I love it and I am sure what I am trying to do is acheivable.

Thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: processs php commands embedded in database table

Post by jackpf »

Do you want to use eval()?

I'm not sure if this is the best option though, I think using include() would be far better. Can you not set up a directory that all domains can access?
TonyBunney
Forum Newbie
Posts: 7
Joined: Thu Jul 30, 2009 8:26 am

Re: processs php commands embedded in database table

Post by TonyBunney »

From what I have read, if allow_url_include set to false, I can not read from the server or is there way I can set up a directory at the server root or at least one level up from the site's home directory to hold shared php files.
I currently have the following directory structure:-
/public_html/
site1.com/
site2.com/
and then most of my scripts in a Scripts subdiretory off of each Site, e.g. /public_html/site1.com/Scripts/ and /public_html/site2.com/Scripts/
if I set up a new directory /public_html/SharedStuff/ and then just include the files directly without going through http or ftp.

I will also look at eval().

Thanks
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: processs php commands embedded in database table

Post by jackpf »

I'd definitely go for setting up a shared directory. Eval() shouldn't really be used unless completely necessary.
TonyBunney
Forum Newbie
Posts: 7
Joined: Thu Jul 30, 2009 8:26 am

Re: processs php commands embedded in database table

Post by TonyBunney »

I was just reading about eval and was put off by what I saw.
I will look at the shared directory method.

Thanks
TonyBunney
Forum Newbie
Posts: 7
Joined: Thu Jul 30, 2009 8:26 am

Re: processs php commands embedded in database table

Post by TonyBunney »

Where do you suggest I create the shared directory and what path do I specify when accessing these shared php file.
TonyBunney
Forum Newbie
Posts: 7
Joined: Thu Jul 30, 2009 8:26 am

Re: processs php commands embedded in database table

Post by TonyBunney »

Not to worry I think I have sorted it.
Thanks for your help.
I am still interested though in how I use the data from the database, if anyone has ideas.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: processs php commands embedded in database table

Post by jackpf »

Well, you should create it in the directory where your directories for your various websites are in.

Like this:

public_html/
includes/
site1.com/
site2.com/

Then you should be able to do something like this:

Code: Select all

include 'public_html/includes/file.php';
And if you want to use data from the database, then run eval() on it.
TonyBunney
Forum Newbie
Posts: 7
Joined: Thu Jul 30, 2009 8:26 am

Re: processs php commands embedded in database table

Post by TonyBunney »

Thanks. It working fine now on the new shared folder.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: processs php commands embedded in database table

Post by jackpf »

Cool :)
Post Reply