MyBB Community Forums

Full Version: Call php code in your template
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Today when i was searching google i found this mod in phpbb.

http://www.phpbb.com/community/viewtopic.php?t=125251

It is very useful mod which has been developed by people of phpBB over there. I thought for a while on how to call a php code on our template system and it happend not to work.

I added the following code global.php.


$code = "some coding or text down here";
ob_start();
eval("?>".$code."<?php ");
$return=ob_get_contents();
ob_end_clean(); 

I used {$return} variable in my header template.
Now when i call the return variable in my header template, it does not execute. I do not know whether my approach is correct or not, so i called a support thread here.

Now i tried to call a php file inside the template which also resulted in the same issue,

$myfriend = get_include_contents('somefilename.php');

function get_include_contents($filename) {
    if (is_file($filename)) {
        ob_start();
        include $filename;
        $vijay = ob_get_contents();
        ob_end_clean();
        return $vijay;
    }
    return false;
}
and then used the variable {$vijay}
Why is this in general support?

Moving....
I thought of first posting it down here, but i thought that i need help for this question and posted it there.
fine sir, i should have read it, ok anyway can u tell me what is the mistake i have made.
eval("?>".$code."<?php ");

Your tags are switched. I'd also like to mention that you don't need them anyway.

http://php.net/eval
Tikitiki Wrote:
eval("?>".$code."<?php ");

Your tags are switched. I'd also like to mention that you don't need them anyway.

http://php.net/eval

It is not a problem even if it is there.

// Are we showing version numbers in the footer?
if($mybb->settings['showvernum'] == "on")
{
	$mybbversion = $mybb->version;
}
else
{
	$mybbversion = '';
}
eval("\$footer = \"".$templates->get("footer")."\";");

Just looked at the global.php and how the mybbversion is called in footer. Evaluates the string given in code_str as PHP code.
I believe what he is saying is that eval($code); would do the job just fine.
Chris Boulton Wrote:I believe what he is saying is that eval($code); would do the job just fine.

yes indeed, even if they are present it does not bring out any problem. for instance

<? and <?PHP may vary according to servers as some accept <? and some need <?PHP. so coding in formal way does not bring any problems though.
vinoth Wrote:
Chris Boulton Wrote:I believe what he is saying is that eval($code); would do the job just fine.

yes indeed, even if they are present it does not bring out any problem. for instance

<? and <?PHP may vary according to servers as some accept <? and some need <?PHP. so coding in formal way does not bring any problems though.

Umm. You don't understand you have ?> and <?php. You are ENDING the PHP by doing ?> and then starting it back up again by doing <?php. It SHOULD BE:

eval("<?php".$code."?> "); 

OR

eval($code); 

Sheesh.
Pages: 1 2