
April 18th, 2005
03:04 PM
ruby on weapon
Status: Offline!
php code parser question
im having a trouble again. im creating a table in my databases to store my websites template.
i've write the class for calling the template from the database and everything work fine until i found out that:
any php code inside the template wont be parsed!
in example, i create a template named "head" like this:
<?php
<html>
<title>$title</title>
$usecss
$metacode
</head>
<body>
?>
then i call the template with:
<?php
$skin->maketmp("head");
?>
it didnt output the value of the variable. instead, the variables still as is.
i've try using eval() or \$ but neither are work.
is there anybody can help me?
thanks much and sorry for the english
___________________
digitalDream // complete Webdesign solution //
- - - - - - [ end signature ] - - - - - -

April 18th, 2005
03:19 PM
Neverside Newbie
Status: Offline!
<?php
<html>
<title><?php $title; ?></title>
<?php
$usecss
$metacode
?>
</head>
<body>
?>
else it will think it's html output not php
Last edited by no3o5, April 18th, 2005 03:19 PM (Edited 1 times)

April 18th, 2005
04:27 PM
ruby on weapon
Status: Offline!
ok thanks for the answer. though i think it's not gonna work.
but why must we using <? and ?> ? templates in vBulletin didnt required <? and ?> if there's a php code inside.
ill give it a shot though
___________________
digitalDream // complete Webdesign solution //
- - - - - - [ end signature ] - - - - - -

April 18th, 2005
10:27 PM
Neverside Newbie
Status: Offline!
<?php
print <<<EOF
<html>
<title>$title</title>
$usecss
$metacode
</head>
<body>
EOF;
?>
Should also work if you'd like to keep the html a little more tidy
I havn't used that in a while, but should still work.
___________________
Andy

April 18th, 2005
11:36 PM
Neversidian
Status: Offline!
just take away the top <?php and bottom ?> then do something like
<?php
$var = 'print <<<EOF
'. $skin->maketmp("head").'
EOF;';
eval($var);
?>
Although i disagree with this method, it will work.
there are security risks with this, so doube, triple, and quadruple check the variables that are in your templates, and any data that a user submits
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

April 18th, 2005
11:45 PM
with Mr. Jones
Status: Offline!
Whitelist user input, not blacklist.
IE, define what is OK, not whats not.
Say this must be an integer
rather then
Must not be a string or special characters or hex or or or
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

April 19th, 2005
03:34 AM
ruby on weapon
Status: Offline!
thanks all. i'll give it a try soon
i still dont understand why vbulletin can make it so easy
___________________
digitalDream // complete Webdesign solution //
- - - - - - [ end signature ] - - - - - -

April 19th, 2005
06:04 AM
Neversidian
Status: Offline!
they eval the values like i said afaik
___________________
Neverside Development Director
PHP Snippets
BigToach.com - IT WORKS, TOACHY!

April 19th, 2005
10:17 AM
ruby on weapon
Status: Offline!
here is my template.php
<?php
class template
{
var $tmpname;
function maketmp($name)
{
$sql = mysql_query("SELECT * from template where tmpname = '$name'");
while($tp=mysql_fetch_array($sql))
{
$blah = $tp["template"];
echo $blah;
}
}
function get($name)
{
include "../tpl/". $name .".inc";
}
}
$skin = new template;
?>
and this is my index.php where i call the template
<?php
if(is_logged_in())
{
# show content here
switch($_GET["t"])
{
case 'root':
$var = 'print <<<EOF
'. $skin->maketmp("admin_index_root").'
EOF;';
eval($var);
break;
}
}
?>
and the template of admin_index_root :
<?php
<div class="logodiv"><img src="../img/logotop.jpg" alt="kioku.NET" /><img src="../img/top.jpg" /></div>
<div class="bgdiv">
<!-- left table -->
<div class="left">
<div class="category"><img src="../img/journal.gif" /></div>
<!-- display news -->
<div class="newstitle">testttttttt</div>
<p class="newstext">
bla bla testing 1 2 3</p>
<!-- end display news -->
</div>
<!-- end left table -->
<!-- right table -->
<div class="right">
<div class="category" style="margin-bottom: 7px;"><img src="../img/navigation.gif" /></div>
$objlink = new alink();
$objlink->newlink("main page", "index.fx", "", "nav");
$objlink->newlink("portfolio", "porto.fx", "", "nav");
$objlink->newlink("showcase", "showcase.fx", "", "nav");
$objlink->newlink("respected", "index.fx?bring=link", "", "nav");
$objlink->newlink("contact me", "index.fx?bring=contact", "", "nav");
<br /><br />
<div class="category"><img src="../img/news.gif" /></div>
</div>
<!-- end right table -->
</div>
<div class="logodiv"><img src="../img/bottom.jpg" /></div>
?>
didnt work for me. maybe there's something wrong with my codes? if anyone can fix it, i'll be very happy
thanks
___________________
digitalDream // complete Webdesign solution //
- - - - - - [ end signature ] - - - - - -
Last edited by DigitalDream, April 19th, 2005 10:21 AM (Edited 1 times)