MyBB Community Forums

Full Version: Using PHP with Page Manager?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I understand that PHP isn't allowed in templates under MyBB's code. I recently downloaded PHP Manager to be able to create PHP files. However, when I select the no option when creating a page

[Image: 4c25505ae6a070514788803a548bd0a2.png]

I can use PHP. It works, but it's not quite what I want. A blank screen with some PHP on it isn't what I had in mind. I wanted the page to still look like the forum but have a content box where I can run PHP. After some looking up I found out I can recreate the basic template with the selection still set to no. You would think this would allow you to run PHP code, however, it does not. Here is the code for the page I used.

<?php
global $headerinclude, $header, $theme, $footer, $templates, $lang, $mybb;
if ($mybb->user['usergroup'] == "6") 
{
$a='<br>Sorry you cannot do that';
$av="<br>Hello ".$mybb->user['username'];}

elseif ($mybb->user['usergroup'] == "4") 
{$a="<br>".$mybb->settings['bbname'];
$av="<br>Hello ".$mybb->user['username'];
$b="<br>Email :- ".$mybb->settings['adminemail'];
}
//echo $av;
$template = '<html>
<head>
<title>' . $pages['name'] . '</title>
{$headerinclude}
</head>
<body>
{$header}
{$errors}
<table border="0" cellspacing="0" cellpadding="0" class="tborder2">
<?php echo "test"; ?>
</table>

{$footer}
</body>
</html>';

$template = str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page = \"" . $template . "\";");

output_page($page);

?>

http://i.gyazo.com/d307db84d7ea71331cd5ee5ce8c4f8bc.png

My page looks perfect but it will not execute ANY PHP code whatsoever. It will execute HTML, but not PHP.

Upon looking up my problem I found a neat little code that allows this to happen called "PHP and Template Conditionals", which is an amazing plugin btw. It allows me to use PHP in my templates, but it will not allow me to use PHP with Page Manager. This has to be an easy fix but I just can't find out how to do it.
I believe that is beyond the limitations of page manager. Something like this may be more along the lines of what you are looking for. This tutorial uses templates, but you could execute PHP code the same way using something like this for the template instead:

<html>
<head>
<title>{$mybb->settings[bbname]}</title>
{$headerinclude}
</head>
<body>
{$header}
<br />
{$pagecontent}
{$footer}
</body>
</html>

Then simply put whatever you want your page content to be as evaluated HTML and make sure it's in the $pagecontent variable before the eval () line in your PHP page. For example:

<?php

define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

add_breadcrumb("Rules page", "rules.php"); // (2)

$pagecontent = "my content! ". "I am executing PHP code!";
eval("\$rules = \"".$templates->get("rules")."\";"); // (3)
output_page($rules); // (4)
?>

http://community.mybb.com/thread-6615.html
(2014-09-23, 05:38 AM)Darth Apple Wrote: [ -> ]I believe that is beyond the limitations of page manager. Something like this may be more along the lines of what you are looking for. This tutorial uses templates, but you could execute PHP code the same way using something like this for the template instead:


<html>
<head>
<title>{$mybb->settings[bbname]}</title>
{$headerinclude}
</head>
<body>
{$header}
<br />
{$pagecontent}
{$footer}
</body>
</html>

Then simply put whatever you want your page content to be as evaluated HTML and make sure it's in the $pagecontent variable before the eval () line in your PHP page. For example:


<?php

define('IN_MYBB', 1); // (1a)
require "./global.php"; // (1b)

add_breadcrumb("Rules page", "rules.php"); // (2)

$pagecontent = "my content! ". "I am executing PHP code!";
eval("\$rules = \"".$templates->get("rules")."\";"); // (3)
output_page($rules); // (4)
?>

http://community.mybb.com/thread-6615.html

I hate to ask but do you know what is limiting Page Manager from being able to run PHP? I'm having trouble believing that this task is completely beyond the limitations of page manager. I would normally choose your route but I have quite a bit of pages I need to do and using that method might make it very confusing.