Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Rene Kluwen  >  NtxFile  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Sample usage
Class: NtxFile
Reads CA/Clipper NTX index files
Author: By
Last change:
Date: 2002-08-15 23:40
Size: 1,451 bytes
 

Contents

Class file image Download
<?

require("ntxclass.php");

function 
myopen($dbname)
// this function opens the dbase file
{
        
$path "/path/to/dbase/file/";
        
$fname $path strtoupper($dbname);
        
$res dbase_open($fname0);
        if (!
$res) {
                die(
"Cannot open $dbname");
        }
        return 
$res;
}

function 
dumprec($rec)
// this function dumps the dbase record
{
        echo 
"<p>Info about record: <u>" $rec["FIRSTNAME"] . " " . ["LASTNAME"] . "</u></p>\n";
        
reset($rec);
        echo 
"<table border=1>";
        
$cnt 0;
        while (list(
$key$val) = each($rec)) {
                
// hide password from user
                
$typ $key == "PASSWORD" "PASSWORD" "TEXT";
                
$val $key == "PASSWORD" "XXXXXX" $val;
                echo 
"<tr><td>$key</td><td>:</td><td><input type=$typ value=\"$val\"></td></tr>\n";
                if (
$cnt++ > 15) break;
        }
        echo 
"</table>";
}

// set the password
// usually we get this from a form
$password "secret";

// open the dbase file and the index file
$db myopen("users.dbf");
$ntx = new NtxFile("userpass.ntx");

// the following is as we would do in clipper
$res $ntx->Seek($password);

if (
$res === false) {
    echo 
"<p>User Not Found</p>";
}
else {
    
// At this point, $res holds the record number
    
$rec dbase_get_record_with_names($db$res);
    
dumprec($rec);
}
?>