WebGet action

It may be necessary to fetch dynamically geneerated data from other web pages and show these into a section of a Wikka-page.
The presented solution is to have a very simple syntax to fetch external data from a given URL.
The code was developed against Wikka so there are no guarantees that this will work in any other versions.

This action is maintained by RubenOlsen Ruben Olsen

How to use it

After you have installed this code, you can then use the action {{webget URL="http://where/to/fetch/data"}} - and that is about everything you need to know about this action

Let's say you have a set of data files in directory. You could of course manually enter these files in the Wikka-page and every time the content of the directory changed, you had to update the page again. Instead you create a small PHP function which list the content of the directory, sorted in the correct order and returned each filename found with a simple BR-tag at the end. No fancy HTML or nothing. Really a self maintained solution. Let's say the URL for this PHP script was http://internalserver/listfiles.php - to embed the file list into a Wikka-page, just enter {{wegbet URL="http://internalserver/listfiles.php"}} where appropriate.

Beware of the following security issue

The webget action fetches data without discrimination of the content. If there are Java Scripts that may pose a security threat, the webget action will carry this security threat into your Wikka-page! Fetch only data you have full control over, or are deemed to be 100% safe.


The webget action is not a web spider, it will only fetch a single URL. Currently there are no sane error checks either like if data can not be sucsessfully fetched.

How to install it

We are going to add one program file to the Wikka actions folder.

First you need to locate the directory where your Wikka is installed. Then locate the actions folder - if you have used Wikka-actions, you will notice a lot of file names corresponding to the name of Wikka-actions.

Save the follwing code (use the grab button) as webget.php in the actions folder.
  1. <?php
  2. /**
  3. * Does a RAW simple http-get  - beware of cross scripting issues
  4. *
  5. * Syntax:
  6. *   {{webget URL="http://address/to/fetch/data/from"}}  
  7. *
  8. * @author  {@link http://wikkawiki.org/RubenOlsen Ruben Olsen} (further notes)
  9. * @copyright Copyright © 2007, Voop AS
  10. *
  11. * @package  Actions
  12. * @name     webget
  13. *
  14. * @version    1.0
  15. *
  16. * @input    string $URL mandatory: The URL where data exists
  17. * @output   Data from $URL
  18. *
  19. * @documentation  {@link http://wikkawiki.org/TBA}
  20. *
  21. * @todo   Fix XSS problems and provide better error handling.
  22. *
  23. */
  25. $URL = $vars[URL];
  26. $FileHandle = fopen($URL,"r");
  28. while (!feof($FileHandle)) {
  29.   print fread($FileHandle, 1024);
  30. }
  31. fclose($FileHandle);
  32. ?>

You are now ready If something does not work yet, leave me a comment. --RubenOlsen

How it works

Using the PHP fopen() function, data is retrieved from the URL source and printed out. The fopen() function is a clever little fellow knowing a thing or two about fetching data from a URL (which can be http, ftp, file, etc).


First version

This page is in the category CategoryUserContributions.
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki