1

I am learning a chat application in php, I am configuring the project and stuck with the following error

In my it is showing all the code in main.php with the followin error,
Fatal error: Class 'SimpleLoginSystem' not found in C:\xampp\htdocs\chatApp\main.php on line 14

my index.html is :

   <frameset rows="65%,35%" framespacing="1" frameborder="yes" border="1" bordercolor="#FF0000">
   <frame src="messages.php" name="main_frame">
   <frame src="main.php" name="login_frame" scrolling="no" noresize target="middle">
</frameset>

my main.php is :

 <?php

// set error reporting level
echo "php ::::::::::::::::::::::::::::::::::"+phpversion();
if (version_compare(phpversion(), "5.3.0", ">=") == 1)
 error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
else
 error_reporting(E_ALL & ~E_NOTICE);

require_once('inc/login.inc.php');
require_once('inc/chat.inc.php');

// initialization of login system and generation code
$oSimpleLoginSystem = new SimpleLoginSystem();

$oSimpleChat = new SimpleChat();

// draw login box
echo $oSimpleLoginSystem->getLoginBox();

// draw chat application
$sChatResult = 'Need login before using';
if ($_COOKIE['member_name'] && $_COOKIE['member_pass']) {
 if ($oSimpleLoginSystem->check_login($_COOKIE['member_name'], $_COOKIE['member_pass'])) {
 $sChatResult = $oSimpleChat->acceptMessages();
 }
}
echo $sChatResult;

?>

my login.inc.php file is :

<?

// class SimpleLoginSystem
class SimpleLoginSystem {

// variables
var $aExistedMembers; // Existed members array


// constructor
function SimpleLoginSystem() {
    $this->aExistedMembers = array(
        'User1' => 'd8578edf8458ce06fbc5bb76a58c5ca4',
        'User2' => 'd8578edf8458ce06fbc5bb76a58c5ca4',
        'User3' => 'd8578edf8458ce06fbc5bb76a58c5ca4'
    );
    echo "ssss";
}

function getLoginBox() {
    ob_start();
    require_once('login_form.html');
    echo "In login_inc.php";
    $sLoginForm = ob_get_clean();

    $sLogoutForm = '<a href="'.$_SERVER['PHP_SELF'].'?logout=1">logout</a>';

    if ((int)$_REQUEST['logout'] == 1) {
        if (isset($_COOKIE['member_name']) && isset($_COOKIE['member_pass']))
            $this->simple_logout();
    }

    if ($_REQUEST['username'] && $_REQUEST['password']) {
        if ($this->check_login($_REQUEST['username'], MD5($_REQUEST['password']))) {
            $this->simple_login($_REQUEST['username'], $_REQUEST['password']);
            return 'Hello ' . $_REQUEST['username'] . '! ' . $sLogoutForm;
        } else {
            return 'Username or Password is incorrect' . $sLoginForm;
        }
    } else {
        if ($_COOKIE['member_name'] && $_COOKIE['member_pass']) {
            if ($this->check_login($_COOKIE['member_name'], $_COOKIE['member_pass'])) {
                return 'Hello ' . $_COOKIE['member_name'] . '! ' . $sLogoutForm;
            }
        }
        return $sLoginForm;
    }
}

function simple_login($sName, $sPass) {
    $this->simple_logout();

    $sMd5Password = MD5($sPass);

    $iCookieTime = time() + 24*60*60*30;
    setcookie("member_name", $sName, $iCookieTime, '/');
    $_COOKIE['member_name'] = $sName;
    setcookie("member_pass", $sMd5Password, $iCookieTime, '/');
    $_COOKIE['member_pass'] = $sMd5Password;
}

function simple_logout() {
    setcookie('member_name', '', time() - 96 * 3600, '/');
    setcookie('member_pass', '', time() - 96 * 3600, '/');

    unset($_COOKIE['member_name']);
    unset($_COOKIE['member_pass']);
}

function check_login($sName, $sPass) {
    return ($this->aExistedMembers[$sName] == $sPass);
}
}

?>

Pls help me... Thanks in advance..

shaan
  • 96
  • 9
  • 1
    You are clearly trying to instantiate an object for which PHP cannot find your class definition for. Make sure you include the file which it is defined in or define an autoloader to do it for you. – John Conde Mar 08 '14 at 02:21
  • 1
    I stopped reading after `frameset`, however do you include the files where the classes are? – Royal Bg Mar 08 '14 at 02:21
  • 2
    Your `login.php` uses the short open tag `` instead of ` – Michael Berkowski Mar 08 '14 at 02:24
  • hi @JohnConde I included the file for SimpleLoginSystem in login.inc.php – shaan Mar 08 '14 at 02:24
  • Your code, the HTML and the PHP one, is obsolete. Consider switching to standards from this decade – Royal Bg Mar 08 '14 at 02:25
  • [Here are the official PHP docs](http://www.php.net/manual/en/language.oop5.php) on classes and objects. The `var` keyword is obsolete. Instead you should be declaring `public/private/protected` visibility on class properties and methods. – Michael Berkowski Mar 08 '14 at 02:27
  • hi @MichaelBerkowski you are right I didn't see the tag now i added it is working ans the messages are saving in DB too, i am now working on retriving it.. Thanks U man :) – shaan Mar 08 '14 at 02:41

0 Answers0