Location: PHPKode > projects > FreiChatX > freichat/server/XC/joomla.php
<?php
$jon=null;


$jon->id=null;
$jon->logged="false";

session_start();
 require("../../arg.php");

// require("../../define.php");
         //$Xmain->db = ADONewConnection($con);
       // $res = $Xmain->db->Connect($host, $username, $password, $client_db_name);
 try {
              $db = new PDO('mysql:host='.$host.';dbname='.$client_db_name, $username, $password);

 } catch (PDOException $e)
 {
    //$this->freichat_debug("XC-> unable to connect to database. Error : ".$e->getMessage());
	$jon->message="XC-> unable to connect to database".$e->getMessage();
	echo json_encode($jon);
    die();
}

            //$this->freichat_debug("connected to database successfully");
            $db->query("SET CHARACTER SET utf8");


 if(isset($_SESSION['username']))
 {
 //echo 'al_log';
 }
if(isset($_REQUEST['username']))
{
	$username=$_REQUEST['username'];
	$password=$_REQUEST['password'];
	$id = $_REQUEST['password'];
	$query="SELECT * FROM ".$db_prefix."users WHERE username='$username'";
	$result=$db->query($query);
	//var_dump($result);
	//xclog($result.$query);
	$result=$result->fetch();
	if($result==false)
	{
			$jon->message="invalid u/pwd";
			echo json_encode($jon);
	}
	else
	{
		//$result=$result->fetch();
		//var_dump($result);
		$words=explode(":",$result['password']);
		if(!isset($words[1])){$words[1]="";}
		$pword=$words[0];
		$hash=$words[1];
		$newhash=md5($password.$hash);
		if($newhash==$pword)
		{

		 //$_SESSION['username']=$username;
		// $_SESSION['id']=$id=$result->fields['id'];
		             $_SESSION[$uid.'usr_name']=$username;
             $_SESSION[$uid.'usr_ses_id']=$result['id'];
			 $_SESSION[$uid.'is_guest']=0;
			 $_SESSION[$uid.'is_xc']=true;
		 $gid=$result['gid'];
		 $time=time();
		 $sid=$time.$username;
		 $jon->logged="true";
		 
		 $insert_name=$username;
		 if($displayname=='name'){
			$insert_name=$result['name'];
		 }

			//check if session exits
				$result=$db->query("SELECT * FROM ".$db_prefix."session WHERE username='$username'");
				$result=$result->fetch();
					if($result==false)
					{//$id=$db->fields['id'];
						$query="INSERT INTO ".$db_prefix."session (username,time,session_id,guest,userid,usertype,gid,client_id)
							VALUES('$insert_name','$time','$sid',0,$id,'Registered',$gid,0)";
						$db->query($query);
					}
					else
					{
						$query="UPDATE ".$db_prefix."session SET time='$time' WHERE username='$username'";
						$db->query($query);
					}

			echo json_encode($jon);

		}
		else
		{
			$jon->message="invalid u/p";
			echo json_encode($jon);
		}

	}

}
else
{
$jon->message="request not sent";
			echo json_encode($jon);
}


?>
Return current item: FreiChatX