Advertisement:

Author Topic: Use FireFox, FireBug and FirePHP to mod SMF  (Read 19584 times)

Offline SlammedDime

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,280
  • School of Air Ride
    • matt.zuba on Facebook
    • @mattzuba on Twitter
    • ZubaFitness
Use FireFox, FireBug and FirePHP to mod SMF
« on: August 16, 2009, 04:47:25 AM »
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:
Code: [Select]
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.
« Last Edit: August 21, 2009, 04:56:47 PM by SlammedDime »
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

bloc

  • Guest
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #1 on: August 16, 2009, 05:15:56 AM »
Thanks :) I am gonna try this out, seems to be useful.

Offline Tony Reid

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,149
  • Gender: Male
    • @AbsoluteBreeze on Twitter
    • www.fertilityfriends.co.uk
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #2 on: August 16, 2009, 05:22:43 AM »
Very interesting - I didn't know about firephp.

Thanks!
Tony Reid


My Big Board
www.FertilityFriends.co.uk/forum - An SMF powered forum with over 5 million posts

Offline Joey Smith™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,356
  • Gender: Male
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #3 on: August 16, 2009, 06:16:17 AM »
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!!

bloc

  • Guest
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #4 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. ;)

Offline Joey Smith™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,356
  • Gender: Male
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #5 on: August 16, 2009, 07:07:10 AM »
I've used that before as well, but I never liked the way it just jambs the output up.

bloc

  • Guest
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #6 on: August 16, 2009, 07:19:59 AM »
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 . :)

Offline H

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 21,660
  • Gender: Male
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #7 on: August 16, 2009, 08:05:37 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

  • Guest
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #8 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.

Offline N3RVE

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 8,906
  • Gender: Male
    • N3RVE.COM
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #9 on: August 16, 2009, 09:24:36 AM »
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

Offline [SiNaN]

  • SMF Super Hero
  • *******
  • Posts: 11,524
  • Young and Foolish
    • SimplePortal
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #10 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>';
Former SMF Core Developer | My Mods | SimplePortal

Offline Fustrate

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,474
  • Gender: Male
  • Controller of the rum budget
    • Fustrate on GitHub
    • @Fustrate on Twitter
    • Fustrate
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #11 on: August 16, 2009, 12:52:23 PM »
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
Code: [Select]
<!-- ', print_r($context), ' -->and
Code: [Select]
die(print_r($context));
Steven Hoffman
Former Team Member, 2009-2012

Offline SlammedDime

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,280
  • School of Air Ride
    • matt.zuba on Facebook
    • @mattzuba on Twitter
    • ZubaFitness
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #12 on: August 16, 2009, 01:35:41 PM »
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'.
« Last Edit: August 16, 2009, 01:41:49 PM by SlammedDime »
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Offline Joey Smith™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,356
  • Gender: Male
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #13 on: August 16, 2009, 05:16:46 PM »
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.

Offline GravuTrad

  • Senior Translator
  • SMF Hero
  • *
  • Posts: 8,582
  • Gender: Male
  • One of the french SMF translators
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #14 on: August 17, 2009, 10:02:45 AM »
Very interesting! Thanks SlammedDime!
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.

Offline SlammedDime

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,280
  • School of Air Ride
    • matt.zuba on Facebook
    • @mattzuba on Twitter
    • ZubaFitness
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #15 on: August 21, 2009, 08:12:02 PM »
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...
                     

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,035
    • Arantor on GitHub
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #16 on: August 21, 2009, 09:34:20 PM »
Sticky please!
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline SlammedDime

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,280
  • School of Air Ride
    • matt.zuba on Facebook
    • @mattzuba on Twitter
    • ZubaFitness
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 68,035
    • Arantor on GitHub
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #18 on: August 21, 2009, 10:19:43 PM »
Ah, cool. As long as it's prominent :)
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

You either die a hero or live long enough to see yourself become the villain. It seems you have chosen which, and now I must do the same.

Offline kai920

  • Sr. Member
  • ****
  • Posts: 855
  • Gender: Male
  • its != it's
Re: Use FireFox, FireBug and FirePHP to mod SMF
« Reply #19 on: December 15, 2009, 10:56:39 AM »
Thanks SlammedDime, very informative post.