Forum Moderators: coopster
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?
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
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.
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
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.