Sidebar Gadget Manager: Implementation Notes

I’m currently installing the show/hide sidebar gadgets script, from scriptygoddess. Because I don’t want to have the script included on every single bloody page, file, and MT template, I’m hiding it in a layer of includes which have caused a couple problems. The extended entry has the gory details.

Setup: I’m using version 1 of the script. If y’all want to change the order of the sidebar boxes, y’all can suck it. Also, I want most of my pages to include() the script stored in a file called sidebar.php.

Problem: The script will be called from an arbitrary location, and I can’t just send people back to the main index every time, or to a naked sidebar.php; I need a variable that reliably refers to the URL in which the sidebar has been included.

Answer: PHP_SELF

Problem Two: the setcookie() function can’t be run in the middle of a document; it needs to go in with the HTTP headers, before the first hint of HTML tags. If you try, setcookie() will fail with the following warning message:

Warning: Cannot modify header information - headers already sent by (output started at /home/greengabbro/public_html/pimpin.php:7) in /home/greengabbro/public_html/sidebar.php on line 16

With no cookie, the script appears to work – until you refresh the page and all the gadgets are switched back to their default status.

Answer: there are two possibilities:

  1. Add the cookie code at the top of every page on which I plan to include the sidebar. I tried doing this with another include(), but for some reason it only worked when I put the code into the actual file. Solution: use an MT Template Module.
  2. Play with output buffering.

Post a Comment

Your email is never published nor shared. Required fields are marked *