|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I have the contents of several pages stored in a database, when a page is accessed, php code grabs the appropriate content and displays it between (included) header and footer code. For example, content code is grabbed from db and stored in $page_content:
PHP Code:
This works fine when the content is HTML, how ever i was trying to include some PHP code, to be executed before the page is displayed, for example PHP Code:
Obviously not what i was after, does anyone have any idea how to retrive code from a db and then execute it? Thanks |
|
#2
|
||||
|
||||
|
This seems like a rather dangerous thing to want to do. For example, what if a system call that attempts to remove all files in the current directory finds its way into your database? If you must do something like this, I'd consider mapping a series of acceptable commands to tag values and scanning the db results for the tags. If they exist, then execute the code using your defined routines for executing it rather than allowing arbitrary code to be executed.
|
|
#3
|
|||
|
|||
|
solution
just in case anyone is interested i have found a solution:
the eval function: PHP Code:
this first escapes to html, incase the contents of $page_content is just a string with no code, then evauates $page_content, then returns to php. Note any code stored in $page_content should be held within php tags, ie PHP Code:
Hope this explains the solution, take into account the warning from dhouston. Thanks to kode_monkey for help with this solution. Last edited by mattp23 : October 2nd, 2003 at 12:21 PM. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > executing php code retrieved from db |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|