News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Use FireFox, FireBug and FirePHP to mod SMF

Started by SlammedDime, August 16, 2009, 04:47:25 AM

Previous topic - Next topic

SlammedDime

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):

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.

Code (For PHP5 users) Select
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'] . ')');
}
}


Code (For PHP4 users) Select
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.



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.



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.



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



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.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

bloc

Thanks :) I am gonna try this out, seems to be useful.

Tony Reid

Very interesting - I didn't know about firephp.

Thanks!
Tony Reid

Tyrsson

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!!
PM at your own risk, some I answer, if they are interesting, some I ignore.

bloc

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. ;)

Tyrsson

I've used that before as well, but I never liked the way it just jambs the output up.
PM at your own risk, some I answer, if they are interesting, some I ignore.

bloc

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 . :)

H

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?) :)
-H
Former Support Team Lead
                              I recommend:
Namecheap (domains)
Fastmail (e-mail)
Linode (VPS)
                             

bloc

Redirects always will be gone lol, so I guess a exit must be performed no matter what there.

N3RVE

Thanks for yet another informative post ;)

-[n3rve]
Ralph "[n3rve]" Otowo
Former Marketing Co-ordinator, Simple Machines.
ralph [at] simplemachines [dot] org                       
Quote"Somewhere, something incredible is waiting to be known." - Carl Sagan

[SiNaN]

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>';
Former SMF Core Developer | My Mods | SimplePortal

Fustrate

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));
Steven Hoffman
Former Team Member, 2009-2012

SlammedDime

#12
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'.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Tyrsson

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.
PM at your own risk, some I answer, if they are interesting, some I ignore.

GravuTrad

On a toujours besoin d'un plus petit que soi! (Petit!Petit!)


Think about Search function before posting.
Pensez à la fonction Recherche avant de poster.

SlammedDime

Just wanna bump this up real quick so it's on the first page. :)
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Arantor



Arantor


kai920


Advertisement: