Forum Moderators: coopster

Message Too Old, No Replies

php files in a mysql database

         

Sarah Atkinson

4:37 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I've been having this problem of my php code not being interpreted. When I view the sorce of my output page i just get something like <?php mycode?>

I think it is because the code is located in a database which other php code places into the page. so my code isn't dumped in till after it is compiled.

Is this what is happening?
IF so, is there anyway around this?

Timotheos

4:51 pm on Jun 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Sarah,

Looks like you realize the problem. Your solution is that you need to use the eval() [php.net] function to parse the string from the database.

Tim

Sarah Atkinson

5:34 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Great.

I guess identifing the problem is usualy one half the way to solving it.. although I think in my case it's only 1/3. now I have to figure out where in my 229 files the function is that dumps the string into the database.

Thank you for the help in figuring out what to do.

btw might this cause some problems down the line if subsquent entries do not contain php code?

This is how it works (i think) I enter in my text which is all php code into a field in a form. that is then turned into a string(let's say ($strx) and added/update to a database. So then I need to add a line $strx=eval($strx); between the string def and the whole database part.

well first does $strx need to be
<?php include '../../header.inc.php';?>

or
include '../../header.inc.php';

second (back to earlier though what if later the $strx is just plain html code?

Will the eval() expression retun an error or just leave it alone.

If it retunrs an error then I will need a condition. Maybe create my own markup tags. search for them in the string and if they are there run the eval() if not skip that function.

Sarah Atkinson

6:31 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I found the page that contains the form that I input text to the database for. It is very complex and stores the data in an array $data["header"]

right now I'm having trouble figuring out where in my 239 lines of code to put the eval() function.

Time to go home though guess I'll work on it tomorrow

Sarah Atkinson

3:01 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



Do I need to uses the eval() when I bring my data out of the database or before I put it in?

Timotheos

3:34 pm on Jun 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Sarah,

I know I suggested eval to you but it makes me wonder if your implementation needs some more thought. Consider this quote from PHP's founder,

If eval() is the answer, you're almost certainly asking the
wrong question. -- Rasmus Lerdorf

It seems strange to me that php code is being stored in the database and you didn't know the when or how about it. It's sort of a little red flag that eval might open some big security implications. Forgive me if you've thought about it and it isn't a problem, better safe then sorry though.

So on to your question... you'd use eval after pulling it out of the database. I'm assuming you have something like this:

$string =
'<h1>This is HTML</h1>
<?php echo "This is PHP";?>
<h2>Here's some more HTML</h2>';

in which case you'd probably have to do something like
eval('?>' . $string . '<?php ');

Tim

Sarah Atkinson

4:15 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



This is for my phplist. We want the sign up pages to look like all of our other pages. I have it set up so that to change the header for the entire site I need change only one file. To do this I use include files. (I love include files)

so the information stored as the header in my database reads something like

<?php
include '../../pageheader.inc.php';
?>

oh and there is php in the include file as well(or at least there will be when I get my project after the next 2 on my to do list done).

same goes with the footer file.

Origionaly i was just going to copy and paste the stuff by hand but when I made changes. However this lead to one small problem. Neglect to account for my own absent mindedness. I failed on more then a few updates to update the list file resulting in broken links and some realy bad flickering. Needless to say the directors were not happy with it. And One has to keep the directors happy.

So now I am trying to..um.. self-proof(?) the site.

Sarah Atkinson

4:56 pm on Jun 9, 2005 (gmt 0)

10+ Year Member



I think I got it