OK, I wrote this script following a tutorial and I believe all the coding is correct. Apparently not, because I'm getting the following error:
Fatal error: Cannot unset string offsets in C:\xampp\xampp\php\pear\Auth.php on line 180
Here's the code:
<?php
require_once("c:\\xampp\\xampp\\php\\pear\\Auth\\Auth.php");
$LEGAL_FUNCS = array( "main", "signup", "logout");
$PAGE['AUTH'] = new Auth("File", "/users/data.txt", "write_login");
$PAGE['msg'] = "";
switchboard();
function switchboard() {
$comms = $GLOBALS['LEGAL_FUNCS'];
$cmd = $_GET['cmd'];
if( empty($cmd) || !in_array( $cmd, $comms)) {
$cmd = $comms[0];
}
$page = $cmd();
if( !empty($page)) {
@include( $page );
}
}
function setMessage( $msg ) {
$GLOBALS['PAGE']['msg'] .= "{$msg}<br />";
}
function authenticate() {
$auth = $GLOBALS['PAGE']['AUTH'];
$auth->start();
if( ! $auth->getAuth()) {
exit();
}
return true;
}
function write_login() {
$auth = $GLOBALS['PAGE']['AUTH'];
if( $auth->getStatus() == AUTH_EXPIRED) {
setMessage("Your session has expired");
}
elseif( $auth->getStatus() == AUTH_WRONG_LOGIN) {
setMessage("Login failed. Try again or sign up");
}
include_once("login.php");
}
function signup() {
if( empty($_GET['username'])) {
return "signup.php";
}
$signup = $GLOBALS['PAGE']['AUTH']->addUser( $_GET['username'], $_GET['password']);
if( $signup instanceof pear_error) {
setMessage( $signup->message );
return "signup.php";
}
setMessage("Signup Succesful!");
return main();
}
function logout() {
$auth = $GLOBALS['PAGE']['AUTH'];
authenticate();
$auth->logout();
setMessage($auth->getUsername()." logged out");
}
function main() {
authenticate();
return "main.php";
}
?>
Can anyone help?