If you want to have very dynamic widgets, you can install PHP code widget. This plugin will allow you to insert PHP code directly in widgets. The widgets containing PHP code can then be added to a sidebar or a footer. This is pretty convenient if you need to run custom code but you don’t want to register your own widgets.
For security reasons, only users with the right capabilities can insert PHP code in widgets.