Problem with ajax im

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryan2345
    New Member
    • Mar 2008
    • 26

    Problem with ajax im

    Hi,
    Ive downloaded ajax im messenger. I want to integrate it with my project.
    Project is in PHP and MySql.
    I already have a login page in my project. I wanted that it should work with the same login page.
    I didnt wanted to use the ajaxim login page.
    Is it possible to do it. How can it be done.
    I tried learning the code but couldnt make the changes i needed.
    Can you plz guide me with this
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by ryan2345
    Hi,
    Ive downloaded ajax im messenger. I want to integrate it with my project.
    Project is in PHP and MySql.
    I already have a login page in my project. I wanted that it should work with the same login page.
    I didnt wanted to use the ajaxim login page.
    Is it possible to do it. How can it be done.
    I tried learning the code but couldnt make the changes i needed.
    Can you plz guide me with this
    The Ajax login might be setting some cookies or session. Do the same with your PHP code.
    Or in the Ajax IM page, if its validating some cookies, change the name of cookie to the one you are creating in your login page.

    Comment

    • ryan2345
      New Member
      • Mar 2008
      • 26

      #3
      It is seting session and i hve also used sessioms in my login page. But still couldnt get it. I ve pasted part of the file i think that needs to be changed.

      [code=php]
      <?php
      require('config .php');

      include('json.p hp');

      // string sanitizer - only alphanumerics //
      function sanitize_alphan um($string, $min='', $max='')
      {
      $string = preg_replace('/[^a-zA-Z0-9\s]/', '', $string);
      $len = strlen($string) ;
      if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
      return FALSE;
      return $string;
      }

      // connect to database //
      $link = mysql_connect($ sql_host, $sql_user, $sql_pass);
      mysql_select_db ($sql_db);
      mysql_query('SE T NAMES \'utf8\'');

      session_start() ;

      class Ajax_IM {
      function Ajax_IM($call) {
      $this->json = new JSON_obj();

      $this->username = $_SESSION['username'];
      $this->password = $_SESSION['password'];

      // run the garbage collector (chance run)
      $this->gc();

      // figure out which action we need to execute,
      // then execute it and print the output
      switch($call) {
      case 'login':
      print $this->login(strtolow er($_POST['username']), $_POST['password']);
      break;

      case 'logout':
      print $this->logout();
      break;

      case 'ping':
      print $this->ping($_POST['away']);
      break;

      case 'send':
      print $this->send($_POST['recipient'], $_POST['message'], $_POST['font'], $_POST['fontsize'], $_POST['fontcolor'], $_POST['bold'], $_POST['italic'], $_POST['underline'], $_POST['chatroom']);
      break;

      case 'addbuddy':
      print $this->addBuddy(strto lower($_POST['username']), $_POST['group']);
      break;

      case 'removebuddy':
      print $this->removeBuddy($_ POST['username']);
      break;

      case 'blockbuddy':
      print $this->blockBuddy($_P OST['username'], ($_POST['status']?$_POST['status']:0));
      break;

      case 'removegroup':
      print $this->removeGroup($_ POST['group']);
      break;

      case 'register':
      print $this->register($_POS T['username'], $_POST['password'], $_POST['email']);
      break;

      case 'isuser':
      print $this->isUser(strtolo wer($_POST['username']));
      break;

      case 'reset':
      print $this->reset($_POST['email']);
      break;

      case 'pwdchange':
      print $this->passwordChange ($_POST['password'], $_POST['newpwd']);
      break;

      case 'joinroom':
      print $this->joinRoom($_POS T['room']);
      break;

      case 'leaveroom':
      print $this->leaveRoom($_PO ST['room']);
      break;

      case 'roomlist':
      print $this->roomList();
      break;
      }
      }

      /**
      * Logs the user in and sets the session for the user.
      *
      * @return JSON object of buddies/blocked users if it usr was successfully logged in, error string otherwise
      * @author Joshua Gross
      **/
      function login($username , $password) {
      $user = $this->checkInfo($use rname, $password, array('admin', 'banned'));
      if(!$user) return 'invalid';
      if($user['banned'] == 1) return 'banned';

      $_SESSION['username'] = $username;
      $_SESSION['password'] = $password;
      $_SESSION['admin'] = $user['admin'];

      $set_status = mysql_query('UP DATE ' . SQL_PREFIX . 'users SET is_online=1, last_ip=\'' . $_SERVER['REMOTE_ADDR'] . '\' WHERE username=\'' . $username . '\'');

      $buddylist = $this->getBuddylist($ username, false);
      $blocklist = $this->getBlocklist($ username);

      $this->userEvent($use rname, $buddylist, 'status', array('status'= >1));

      $buddylist = $this->getBuddylistOn line($username) ;
      if(count($buddy list) > 0)
      $output['buddy'] = $this->json->encode($buddyl ist);
      else
      $output['buddy'] = array();

      $output['blocked'] = $this->json->encode($blockl ist);

      $output['admin'] = $user['admin'];

      return $this->json->encode($output );
      }

      /**
      * Logs the user out and destroys the session.
      *
      * @return String 'logged_out'
      * @author Joshua Gross
      **/
      function logout() {
      if(!$this->checkInfo($thi s->username, $this->password)) return 'invalid';

      $buddylist = $this->getBuddylist($ this->username, false);

      $set_status = mysql_query('UP DATE ' . SQL_PREFIX . 'users SET is_online=0, last_ping=\'' . time() . '\' WHERE username=\'' . $this->username . '\'');

      ?>
      [/code]
      The session in my form is $_SESSION['username']
      I couldnt understand what is to be done. Can you plz help me.
      Thanks.

      Comment

      • ryan2345
        New Member
        • Mar 2008
        • 26

        #4
        The login page for ajax im is index.html
        I tried editing it. I removed the new user register and forgot password part from it.
        Now i want that when a user is logged in my sitr then just by clicking on the im option he should be able to chat without logging in again.
        The code of index.html is here:
        Plz help me out.
        Attached Files

        Comment

        Working...