WordPress already comes with a basic text widget that you can use to show ads and other simple content. In certain cases, you may want to run PHP code in your widgets. The PHP Code Widget plugin can help. It allows you to execute PHP code in your widgets. You will simply have to enclose your code in the proper opening and closing tags, and the rest is easy.
This plugin allows anybody with admin and editor roles to execute code through widgets. Probably shouldn’t be used as a long term option for security reasons. PHP Code Widget is available as a free download.