469,330 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

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
Mar 25 '08 #1
3 2056
hsriat
1,654 Expert 1GB
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.
Mar 25 '08 #2
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.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require('config.php');
  3.  
  4. include('json.php');
  5.  
  6. // string sanitizer - only alphanumerics //
  7. function sanitize_alphanum($string, $min='', $max='')
  8. {
  9.    $string = preg_replace('/[^a-zA-Z0-9\s]/', '', $string);
  10.    $len = strlen($string);
  11.    if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max)))
  12.      return FALSE;
  13.    return $string;
  14. }
  15.  
  16. // connect to database //
  17. $link = mysql_connect($sql_host, $sql_user, $sql_pass);
  18. mysql_select_db($sql_db);
  19. mysql_query('SET NAMES \'utf8\'');
  20.  
  21. session_start();
  22.  
  23. class Ajax_IM {
  24.    function Ajax_IM($call) {
  25.       $this->json = new JSON_obj();
  26.  
  27.       $this->username = $_SESSION['username'];
  28.       $this->password = $_SESSION['password'];
  29.  
  30.       // run the garbage collector (chance run)
  31.       $this->gc();
  32.  
  33.       // figure out which action we need to execute,
  34.       // then execute it and print the output
  35.       switch($call) {
  36.          case 'login':
  37.             print $this->login(strtolower($_POST['username']), $_POST['password']);
  38.          break;
  39.  
  40.          case 'logout':
  41.             print $this->logout();
  42.          break;
  43.  
  44.          case 'ping':
  45.             print $this->ping($_POST['away']);
  46.          break;
  47.  
  48.          case 'send':
  49.             print $this->send($_POST['recipient'], $_POST['message'], $_POST['font'], $_POST['fontsize'], $_POST['fontcolor'], $_POST['bold'], $_POST['italic'], $_POST['underline'], $_POST['chatroom']);
  50.          break;
  51.  
  52.          case 'addbuddy':
  53.             print $this->addBuddy(strtolower($_POST['username']), $_POST['group']);
  54.          break;
  55.  
  56.          case 'removebuddy':
  57.             print $this->removeBuddy($_POST['username']);
  58.          break;
  59.  
  60.          case 'blockbuddy':
  61.             print $this->blockBuddy($_POST['username'], ($_POST['status']?$_POST['status']:0));
  62.          break;
  63.  
  64.          case 'removegroup':
  65.             print $this->removeGroup($_POST['group']);
  66.          break;
  67.  
  68.          case 'register':
  69.             print $this->register($_POST['username'], $_POST['password'], $_POST['email']);
  70.          break;
  71.  
  72.          case 'isuser':
  73.             print $this->isUser(strtolower($_POST['username']));
  74.          break;
  75.  
  76.          case 'reset':
  77.             print $this->reset($_POST['email']);
  78.          break;
  79.  
  80.          case 'pwdchange':
  81.             print $this->passwordChange($_POST['password'], $_POST['newpwd']);
  82.          break;
  83.  
  84.          case 'joinroom':
  85.             print $this->joinRoom($_POST['room']);
  86.          break;
  87.  
  88.          case 'leaveroom':
  89.             print $this->leaveRoom($_POST['room']);
  90.          break;
  91.  
  92.          case 'roomlist':
  93.             print $this->roomList();
  94.          break;
  95.       }
  96.    }
  97.  
  98.    /**
  99.     * Logs the user in and sets the session for the user.
  100.     *
  101.     * @return JSON object of buddies/blocked users if it usr was successfully logged in, error string otherwise
  102.     * @author Joshua Gross
  103.     **/
  104.    function login($username, $password) {
  105.       $user = $this->checkInfo($username, $password, array('admin', 'banned'));
  106.       if(!$user) return 'invalid';
  107.       if($user['banned'] == 1) return 'banned';
  108.  
  109.       $_SESSION['username'] = $username;
  110.       $_SESSION['password'] = $password;
  111.       $_SESSION['admin']    = $user['admin'];
  112.  
  113.       $set_status = mysql_query('UPDATE ' . SQL_PREFIX . 'users SET is_online=1, last_ip=\'' . $_SERVER['REMOTE_ADDR'] . '\' WHERE username=\'' . $username . '\'');
  114.  
  115.       $buddylist = $this->getBuddylist($username, false);
  116.       $blocklist = $this->getBlocklist($username);
  117.  
  118.       $this->userEvent($username, $buddylist, 'status', array('status'=>1));         
  119.  
  120.       $buddylist = $this->getBuddylistOnline($username);
  121.       if(count($buddylist) > 0)
  122.          $output['buddy'] = $this->json->encode($buddylist);
  123.       else
  124.          $output['buddy'] = array();
  125.  
  126.       $output['blocked'] = $this->json->encode($blocklist);
  127.  
  128.       $output['admin'] = $user['admin'];
  129.  
  130.       return $this->json->encode($output);
  131.    }
  132.  
  133.    /**
  134.     * Logs the user out and destroys the session.
  135.     *
  136.     * @return String 'logged_out'
  137.     * @author Joshua Gross
  138.     **/
  139.    function logout() {
  140.       if(!$this->checkInfo($this->username, $this->password)) return 'invalid';
  141.  
  142.       $buddylist = $this->getBuddylist($this->username, false);
  143.  
  144.       $set_status = mysql_query('UPDATE ' . SQL_PREFIX . 'users SET is_online=0, last_ping=\'' . time() . '\' WHERE username=\'' . $this->username . '\'');
  145.  
  146.  ?>
  147.  
The session in my form is $_SESSION['username']
I couldnt understand what is to be done. Can you plz help me.
Thanks.
Mar 25 '08 #3
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
File Type: txt index.txt (10.5 KB, 546 views)
Mar 26 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Alok yadav | last post: by
13 posts views Thread by alvinwoon | last post: by
3 posts views Thread by willl69 | last post: by
4 posts views Thread by sheldonlg | last post: by
12 posts views Thread by sheldonlg | last post: by
omerbutt
3 posts views Thread by omerbutt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.