WACSip

Web-based Adult Content Server

A PHP interface for WACS

Contents

Overview

This document is intended for web developers using the php language and wishing to access a WACS server infrastructure from their own pages. Some knowledge of how the WACS system works is required in order to make use of this interface module. For more information on WACS itself, please visit the project page on sourceforge (http://wacsip.sourceforge.net/).

Getting Started

The first step is to include the required modules (Wacs and DB) into your PHP program which mandates use of the required_once directive and then creating an instance of the wacs module:
require_once "wacs.php";
require_once 'DB.php';

$wacs = new Wacs;
 
The second step is to invoke the Wacs php module so it reads the configuration file and checks the security rules for the current connection:
// read the Wacs configuration files
$wacs->read_conf();

// check the auth(entication and authorisation) of this user
$wacs->check_auth( $_SERVER['REMOTE_ADDR'], 0 );
 
The third step is to initialise the database connection. Since some databases require an environment variable to determine where their configuration files have been stored, this needs to be set first. Wacs provides for this and this code will create that environment variable, if needed, and then proceed to establish the database connection itself. Note that you might wish to have completed the output of the HTML header section and started the body by this point so that should the database connection fail, the error message will be visible:
// database initialisation
$dbienv = $wacs->conf_get_attr("database","dbienvvar");
if( ! empty( $dbienv ))
{
        putenv($dbienv."=".$wacs->conf_get_attr("database","dbienvvalue"));
}
$dbhandle= DB::connect( $wacs->conf_get_attr("database","phpdbconnect") );
if( DB::iserror($dbhandle))
{
        print "Can't connect to database\n";
}
 

Generating Output

At this point the Wacs subsystem is operational and you can go ahead with generating the required output. A very simple example is shown here - take a look at the samples directory for slightly more complex examples. The first step is to execute the query and get back some results:
// do db select
//                                    0      1        2          3
$results = $dbhandle->getAll("select mname, modelno, mbigimage, mimage from ".
                        $wacs->conf_get_attr("tables","models").
                        " where mflag = 'C' order by mname");
 
And finally the actual output code which lists the names of those models flagged as Cuties within the Wacs database.
echo "<ul>\n";
while( isset( $results[$entryno] ))
{
	echo "<li>";
	echo "<a href=\"".$wacs->conf_get_attr("server","cgiurl");
	echo "wacsmpthumbs/".$results[$entryno][1]."\">";
	echo $results[$entryno][0]."</a></li>\n";
	$entryno++;
}
echo "</ul>\n";
and finally you finish off the html output. If you take a look at the program simple.php in the samples directory, it is an embedded php version of the above program segments. The faves.php program is basically a slightly more sophisticated version of the same thing written as a conventional program.

For further information on programming for Wacs, refer to the regular wacs documentation. The APIs provided by the perl and php implementations are function call identical whereever possible.


Back to Wacs-PHP documentation