MyBB Community Forums

Full Version: PHP Includes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Is there some reason why php includes don't work when edited in to MyBB?

Shy
What do you mean? Example?
Well when I try to edit in some php code somewhere in a template it just doesn't do anything...

I've even tested something simple like a date print... just doesn't show up, no errors or anything. :|
You cannot add php code to the templates you need to add it to the php files.
and call the code with an $ variable.
Like.
$test = "testing";
and then in the template you have:
{$test}
Which will output -> testing
eh... could be fun...

Thanks!
ok, I've given it a go and just printing out simple test like that is fine but whenever I try some coding it gets unhappy and complains about the header..?

Is the index.php file not a good place to add in the variable?

Here's what I used just as a test:

$test = print date("jS F Y");
Don't use print there, and also if you are trying to add it to the header add it to global.php Smile
$test = date("jS F Y");
hmm ok, tried that with an include this time, just adding in a file with text to test and now getting all kinds of funny errors... which I wasn't so useless at this =/

Warning: Cannot modify header information - headers already sent by (output started at path/file.php:1) in path/forum/inc/functions.php on line 1053


(edited path btw)
You shouldn't directly "print" or "echo" stuff from your files. Try to set your output as a variable and put it in a MyBB template.
Good stuff - this thread has given me a clue on how to get some of the stats data to be available in a different template.

I shall have to try a bit of copying and pasting of code this afternoon and see how it goes, but thus far myBB has proven pretty simple to integrate into my website so I'm pretty hopeful Smile
ajsuk Wrote:hmm ok, tried that with an include this time, just adding in a file with text to test and now getting all kinds of funny errors... which I wasn't so useless at this =/

Warning: Cannot modify header information - headers already sent by (output started at path/file.php:1) in path/forum/inc/functions.php on line 1053


(edited path btw)


Editing some of the .php and lang files directly at the server have proved to be somewhat of a headache and return the likes of the error message you have quoted..

I've seen it probably 30 times.. using MyBB v1.2 Sad

I have got used to d/l'ing the file... edit with WordPad, -> save as TEXT ONLY, ignore the warnings that it contains ansi etc.. -> rename the file at the server to 1+(the file name) for insurance -> reload the edited file to the server..

It has cleared all of the errors as you have mentioned on every occasion; and if more than one file file has been edited, the error messages are in multiples, with all different locations etc... Sad

Off Topic:

If you want to experiment with "Printing" data into existing .php / mixed with html templates, then this would be something you can play with..


<?php 
$mytest = "yourfile.name"; 
$handle = fopen($mytest, 'r'); 
$Data = fread($handle, 8190); 
fclose($handle); 
print $Data; 
?>


It will only handle 8,190 bytes... and the .html file must be changed to a .php extension for it to work. Wink
Pages: 1 2