Jump to content

How to run php code that is stored in a database?


denno020

Recommended Posts

How can I run php code that is stored in a database?

 

I have my pages created by grabbing the contents of a pageBody mySQL table cell, but some pages require further php to be able to display correctly.

 

For example, I have a players page, which will list all players, and some information about them. The players and information is all saved in a players table in my database (separate to the pages table where pageBody is stored). I use simple php to grab all the players and format all of their information so it can be displayed on the page.

 

This is the flow of information that I would like:

  • User clicks on players page
  • browser loads content page (this is a template page), and grabs the pageid from $_GET
  • browser then reads pages table in database to get the pageBody associated with the pageid
  • The pageBody will contain more php, which will run the players script to retrieve the list, and display

 

Doing it the above way will make it much easier to extend the website to include more types of pages that has to run additional php scripts.

The only way I can think of this working is by doing this:

  • user clicks on players page
  • browser loads content page, grabs pageid from $_GET
  • browser checks the pageid for the one associated with players (hard coded into the php script)
  • browser then loads the players.php script instead of going to the database

This above way means that I will need to edit the index.php page everytime I add a new list type (example, coaches, volunteers etc).

 

Anyone have any suggestions? I know my question is long, but I was finding it hard to explain it in an easy to understand way, but I'm still not sure if I have :S.

 

Cheers

Denno

 

Link to comment
Share on other sites

I'll be honest, I didn't really read your post. I will say this though, storing code in a database is generally a poor design choice. You can look at eval, but be aware, it's not nick named evil for nothing. It can pose quite the security risk allowing users to input and then execute php.

 

There are other options around. Google (PHP Javascript parser). I have used a Javascript parser written in PHP in one of my CMS's to good effect. this allows you to create a macro language (using Javascript syntax) with which you can provide your own safe API instead of allowing PHP itself.

 

I'm at work or I would post a link.

Link to comment
Share on other sites

ahk just read it.

 

That seems way involved. I'm only creating a website for my local footy club lol. I'll just go with the option that I didn't want to, and if they want another section or something set up, I'll just have to code that in.. Not ideal, but it will do..

 

Thanks mate.

 

Denno

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.