Page 1 of 1
How to Create a Simple Widget?
Posted: Mon May 19, 2008 8:18 pm
by Chalks
I would like to create a simple widget that anyone could place on their website. All that it would need to do is update (preferably live, but on refresh is fine too) one piece of data. The number of people who care. Like so:

- widget.png (5.28 KiB) Viewed 103 times
I want it to either:
query a database on my server or
load data from a php file on my server
Is it possible to do this with php?
Re: How to Create a Simple Widget?
Posted: Mon May 19, 2008 9:41 pm
by Chalks
This actually turned out to be a lot simpler than I expected it to be.
Code: Select all
<div id="widget">
<object data="http://example.com/widget.php" style="width: 155px; height: 20px;">
</object>
</div>
Anything wrong with doing it that way?
Re: How to Create a Simple Widget?
Posted: Mon May 19, 2008 10:32 pm
by s.dot
What's your widget.php code?
When I needed to do something like that I just used imagestring() to draw on an image and present it through a php script. i.e.: image.php?imageid=xxx
Re: How to Create a Simple Widget?
Posted: Mon May 19, 2008 10:49 pm
by Chalks
widget.php:
Code: Select all
<body onload="count()">
<div style="width: 170px; height: 26px; background-image: url(widget.png); background-repeat: no-repeat;">
<span style="position: absolute; top: 4px; left: 15px; font-size: 14px;">
<span id="count"><?php include 'count.php'; ?></span>
<a href="http://example.com" target="_parent">People Care about this NOW</a>
</span>
</div>
</body>
the count() function refreshes the span "count" every 30 seconds with the new count. If javascript is disabled, it doesn't break anything, just stops the dynamic refreshes. The target="_parent" because I decided to switch to using <iframe> instead of <object> because ie doesn't properly support the object tag. Everything validates with a transitional dtd.