[Solved] Whats wrong with $this!
Posted: Sun Dec 21, 2003 9:27 pm
Sorry for the stupid pun in the topic subject
But right now I'm going crazy trying to understand why I keep getting the error:
Fatal error: Call to a member function on a non-object in /home/duffdesi/public_html/fileshack/uploader/authclass.php on line 47
when trying to use $this in my class.
OK, I have made a user authentication class (class authUser). I made an example page to test out if my errors were working and to my surprise they were not!
Here is the test page (authtest.php)
I purposefully made the $requiredlevel (3) too high so I would get an error. Here is the actual class:
For some reason $this in line 47 (commented above) is causing the error message but I have no idea why! Anyone have any ideas? I have tried renaming the error function and some other things but have had no luck.
But right now I'm going crazy trying to understand why I keep getting the error:
Fatal error: Call to a member function on a non-object in /home/duffdesi/public_html/fileshack/uploader/authclass.php on line 47
when trying to use $this in my class.
OK, I have made a user authentication class (class authUser). I made an example page to test out if my errors were working and to my surprise they were not!
Here is the test page (authtest.php)
Code: Select all
<?php
ob_start(); //needed because of headers
include("authclass.php"); //include class script
$user = new authUser; //start new class
$user->requireAuth(3, "HL"); //call requireAuth function ($requiredlevel, $requiredmod)
echo "You were successfully authenticated!"; //this will only show if requireAuth was successful
?>Code: Select all
<?php
function requireAuth($reqlvl, $reqmod)
{
session_start();
// some stuff
$userlevel = $_SESSION['level'];
$usermod = $_SESSION['mod'];
if ($userlevel >= $reqlvl) //if userlevel greater then or equal to required level
{
if ($usermod == $reqmod || $usermod == "ALL") //if required mod is correct
{
return true; //auth successful
}
else
{
$error = "Access Denied: Incorrect Mod";
$this->error($error);
}
}
else
{
$error = "Access Denied: Incorrect Userlevel";
$this->error($error); // LINE 47!!!
}
}
function error($error)
{
// simplified code
die($error);
}
?>