Sometimes trying to track down what variables hold what and modify your SMF installation can be a royal pain. Between finding out what variables hold what, and where they get their information, it can be time consuming and troublesome, and it sometimes makes it difficult to code when you have to to
print_r() or
die() all over the place to find what you need.
FirePHP is the solution. It will take PHP variables and send them in the HTTP headers when your page is retrieved and then they are displayed in the FireBug console of Firefox. No messy code on the page, easily formatted and colored and easily accessible.
You'll need 4 things to get started (in this order):
- Firefox (http://www.mozilla.com/en-US/firefox/personal.html)
- Firebug (https://addons.mozilla.org/en-US/firefox/downloads/latest/1843/addon-1843-latest.xpi?src=addondetail)
- FirePHP (https://addons.mozilla.org/en-US/firefox/downloads/latest/6149/addon-6149-latest.xpi?src=addondetail)
- FirePHP Core (http://www.firephp.org/HQ/Install.htm) (Choose the 'Download' link)
Once you have downloaded the FirePHP Library, extract it and go into FirePHPCore-
x.x.x > lib and extract FirePHPCore to your root SMF folder (the same place as SSI.php)
Open up your main index.php file in your root SMF directory and copy the proper code block from below to the very top of the file, directly after <?php, but before the SMF comment section.
if (file_exists('FirePHPCore/FirePHP.class.php'))
{
require_once('FirePHPCore/FirePHP.class.php');
$firephp = FirePHP::getInstance(true);
function fp($var)
{
global $firephp;
$debug = debug_backtrace();
$firephp->log($var, basename($debug[0]['file']) . ' (Line: ' . $debug[0]['line'] . ')');
}
}
if (file_exists('FirePHPCore/FirePHP.class.php4'))
{
require_once('FirePHPCore/FirePHP.class.php4');
require_once('FirePHPCore/fb.php4');
$firephp =& FirePHP::getInstance(true);
function fp($var)
{
global $firephp;
$debug = debug_backtrace();
$firephp->log($var, basename($debug[0]['file']) . ' (Line: ' . $debug[0]['line'] . ')');
}
}
That's all there is for setting it up. Now to use it is very very simple. In any spot of your code, when you want to view the output of a variable, simply use the following code:
fp($variable);
Let's look at an example real quick. Let's say that we want to display the value of the $user_info variable in Sources/Display.php right after the 'global' lines in the Display function.
(https://www.simplemachines.org/community/index.php?action=dlattach;topic=331222.0;attach=111773;image)
Now in Firefox, click the small 'bug' icon in the lower right corner of your screen to expand the Firebug console (if not already expanded). All the way to the right you will now see a similar bug, but blue in color. Click on it and make sure there is a check mark next to FirePHP Enabled.
(https://www.simplemachines.org/community/index.php?action=dlattach;topic=331222.0;attach=111775;image)
Now in the Firebug console, click on 'Console' if not already at the front, then click the small down arrow and make sure that 'Enabled' has the dot next to it.
(https://www.simplemachines.org/community/index.php?action=dlattach;topic=331222.0;attach=111777;image)
Do the same with the 'Net' panel.
Now visit any topic on your site and you should see something similar to the following in the console
(https://www.simplemachines.org/community/index.php?action=dlattach;topic=331222.0;attach=111779;image)
It shows you the file and the line that made the
fp() call, and the output of the variable you requested. Mouseover the variable contents to see a popup window with the detail of the variable with pretty colors. Click on the variable contents to cause the popup window to stay up until you close it.
WARNING: Using FirePHP on production sites can expose sensitive information. You must protect the security of your application by disabling FirePHP logging on your live site. You can do this by removing the logging statements before you upload your code or by restricting FirePHP logging to authorized users only.
That's all there is to it. Easy PHP debugging with Firefox, Firebug and FirePHP.
Thanks :) I am gonna try this out, seems to be useful.
Very interesting - I didn't know about firephp.
Thanks!
I just set it up and I must say it rocks.. Dont forget to enable the net panel in firebug. Even with the console on and firephp enable if the net panel is not on it will not work.
Thanks SD this rocks!!
Its working..but I have to say its a bit cumbersome for me lol. I usually add just a print_r() right before body tag and just change that for different global variables I want to check.
But then again I like few - and small - programs running instead of slow monsters. Why do 5 steps when you can do just 1. ;)
I've used that before as well, but I never liked the way it just jambs the output up.
True, I format it into a nice div though, so the page looks as it should - just a little longer lol. But of course, each to its own . :)
Quote from: Bloc on August 16, 2009, 06:57:59 AM
Its working..but I have to say its a bit cumbersome for me lol. I usually add just a print_r() right before body tag and just change that for different global variables I want to check.
But then again I like few - and small - programs running instead of slow monsters. Why do 5 steps when you can do just 1. ;)
This is my method too but I find this is a pain if you're doing something before a redirect as you then have to call die() to actually view your output. I'll give FirePHP a go, now that I know such a thing exists (although I doubt it works with redirects?) :)
Redirects always will be gone lol, so I guess a exit must be performed no matter what there.
Thanks for yet another informative post ;)
-[n3rve]
I haven't tried this too. But I was hoping that it didn't require the fp function call. Not sure what else it could give than print_r and var_dump but I'll give it a go.
Tyrsson, did you use pre to format the text? Something like this would give you a pretty neat info:
echo '<pre>';
print_r($variable);
echo '</pre>';
I just put mine in HTML comments and command-U to see it nicely formatting in the source. I've gotten really good at typing
<!-- ', print_r($context), ' -->
and
die(print_r($context));
Quote from: Bloc on August 16, 2009, 08:59:15 AM
Redirects always will be gone lol, so I guess a exit must be performed no matter what there.
it
DOES in fact work with redirects (at least redirectexit in SMF), because it is simply added to the header output, and the redirect is done in the headers, which makes it great for grabbing form data when it's submitted without having to 'die' or 'exit'.
Quote from: [SiNaN] on August 16, 2009, 11:31:59 AM
I haven't tried this too. But I was hoping that it didn't require the fp function call. Not sure what else it could give than print_r and var_dump but I'll give it a go.
Tyrsson, did you use pre to format the text? Something like this would give you a pretty neat info:
echo '<pre>';
print_r($variable);
echo '</pre>';
Never used that, but I am just getting into this in-depth so I can always use all the info I can get.
Very interesting! Thanks SlammedDime!
Just wanna bump this up real quick so it's on the first page. :)
Sticky please!
http://www.simplemachines.org/community/index.php?topic=214513.0#new
Ah, cool. As long as it's prominent :)
Thanks SlammedDime, very informative post.
how i add these codes inside my running forum, will there be any effect or should i create a "test" sub domain?