Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

MESSENGER ,PROGRAMME CHAT DIRECTEMENT AVEC MON WEB SITE PAS D'IP PAS DES PORTS


Information sur la source

Catégorie :Réseau & Internet Source .NET ( DotNet ) Classé sous : messenger, chat, msn, discuter, messages Niveau : Initié Date de création : 30/05/2007 Date de mise à jour : 05/06/2007 22:11:10 Vu / téléchargé: 12 536 / 970

Note :
7,25 / 10 - par 4 personnes
7,25 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (23)
Ajouter un commentaire et/ou une note

Description

Cliquez pour voir la capture en taille normale
ce programme  utilise  des web services et  les code PHP  et une data base sur mon site pour connecter. tres rapide , et aussi j'ai ajouter  a chaque contact  un inbox pour les message  et aussi liste des contact  et  search pour les contact et plien des truc .........
 

Source

  • //code de la WebService fait par PHP
  • //.....................................................START
  • <?php
  • // server folder : http://egypto.awardspace.com/server/connect.php
  • // Copyright © EGPTO.NET 2006. All rights reserved.
  • //By : Peter Gad Shehata
  • //email: Peter_Gad1@yahoo.com
  • //Phone: 0202-0125669727
  • $client_message = trim($client_message);
  • $client_info ;
  • //$ip = getenv ("REMOTE_ADDR");
  • connect_to_database () ;
  • //$client_message = "login";
  • //$client_info = "id:half_angelpw:0123883491" ;
  • //echo $client_info."<br>" ;
  • //------------
  • switch ($client_message) {
  • //--------------------------------------------------------------------------------case1
  • //hi
  • case 'hi' :
  • echo 'ip:' . $ip ;
  • Break;
  • //--------------------------------------------------------------------------------case2
  • case "login" :
  • $userid = trim(substr ($client_info,3,strpos($client_info , "pw")-3));
  • $userpass = substr ($client_info,strpos($client_info , "pw") +3 , strlen($client_info)-1);
  • //--------------------------------------------------------------------------------case3
  • $result = mysql_query ( "select userid_ , userpass_, username_ from users_login where userid_ = '$userid' ");
  • $row = mysql_fetch_array($result);
  • if ($userid == $row[0] and $userpass == $row[1]){
  • $result = getall_Dlogin ($userid) ;
  • echo "lit"."*/w".$row[2].$result ;
  • exit ;
  • }else{
  • echo 'lif';
  • exit ;
  • }
  • Break;
  • //---------------------------------------------------------------------------------case1
  • case "send new message":
  • $from = trim(substr ($client_info,strpos($client_info , "frm:")+4,strpos($client_info , "to:")-4));
  • $to = trim(substr ($client_info,strpos($client_info , "to:")+3,strpos($client_info , "sub:")-strpos($client_info , "to:")-3));
  • $subject = trim(substr ($client_info,strpos($client_info , "sub:")+4,strpos($client_info , "msg:")-strpos($client_info , "sub:")-4));
  • $message = trim(substr ($client_info,strpos($client_info , "msg:")+4,strpos($client_info , "date:")-strpos($client_info , "msg:")-4));
  • $date = trim(substr ($client_info,strpos($client_info , "date:")+5,strlen($client_info)-1));
  • send_message ($from,$to,$date,$subject,$message);
  • Break;
  • //----------------------------------------------------------------------------------cas5
  • case "show all new messages":
  • $result = dir_myinbox ($client_info,"all new messages");
  • echo "nmg".$result ;
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case6
  • case "delete message":
  • $m_from = trim(substr ($client_info,strpos($client_info , "frm:")+4,strpos($client_info , "date:")-4));
  • $m_date = trim(substr ($client_info,strpos($client_info , "date:")+5,strpos($client_info , "tab:")-strpos($client_info , "date:")-5));
  • $m_table = trim(substr ($client_info,strpos($client_info , "tab:")+4,strlen($client_info)-1));
  • $table = $m_table . '_inbox';
  • mysql_query ( "delete from $table where from_ = '$m_from' and date_ = '$m_date'");
  • echo 'mgd';
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case7
  • case "show all message":
  • dir_myinbox ($client_info,"all messages");
  • Break;
  • //---------------------------------------------------------------------------------- case8
  • case "show all contacts":
  • $c_table = $client_info ;
  • getallcontacts_from_my_list($c_table);
  • Break;
  • //---------------------------------------------------------------------------------- case9
  • case "add a contact":
  • $contact = substr ($client_info ,0,strpos($client_info , "/u*")) ;
  • $username = substr ($client_info ,strpos($client_info , "/u*")+3,strpos($client_info , "/e*")-strpos($client_info , "/u*")-3);
  • $result = add_a_contact($contact,$username);
  • if ($result == "0") {
  • echo 'car';
  • exit ;
  • }elseif ($result == "1"){
  • echo 'cad';
  • exit ;
  • }else{
  • echo 'cau';
  • } exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case10
  • case "remove a contact":
  • $contact = substr ($client_info ,0,strpos($client_info , "/u*")) ;
  • $username = substr ($client_info ,strpos($client_info , "/u*")+3,strpos($client_info , "/e*")-strpos($client_info , "/u*")-3);
  • $result = remove_a_contact($contact,$username);
  • if ($result == 1){
  • echo 'rct';
  • exit ;
  • }else{
  • echo 'rcf';
  • } exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case11
  • case "un/block a contact":
  • $contact = substr ($client_info ,0,strpos($client_info , "/u*")) ;
  • $username = substr ($client_info ,strpos($client_info , "/u*")+3,strpos($client_info , "/e*")-strpos($client_info , "/u*")-3);
  • $result = block_unblock_a_contact($contact,$username);
  • if ($result == 1){
  • //block true
  • echo 'bct';
  • exit ;
  • }elseif ($result == 2){
  • //unblock true
  • echo 'ubc';
  • exit ;
  • }else{
  • echo 'bcf';
  • exit ;
  • }
  • Break;
  • //---------------------------------------------------------------------------------- case12
  • case "read message":
  • $m_from = trim(substr ($client_info,strpos($client_info , "frm:")+4,strpos($client_info , "date:")-4));
  • $m_date = trim(substr ($client_info,strpos($client_info , "date:")+5,strpos($client_info , "tab:")-strpos($client_info , "date:")-5));
  • $m_table = trim(substr ($client_info,strpos($client_info , "tab:")+4,strlen($client_info)-1));
  • $table = $m_table . '_inbox';
  • Mysql_query("update $table set read_ = '0' where from_ = '$m_from' and date_ ='$m_date'");
  • echo 'mgr';
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case13
  • case "change my status":
  • $nickname = substr ($client_info ,0,strpos($client_info , "/s*")) ;
  • $status = substr ($client_info ,strpos($client_info , "/s*")+3,strpos($client_info , "/e*")-strpos($client_info , "/s*")-3);
  • change_status($nickname,$status);
  • echo 'usg';
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case14
  • case "get contact profile":
  • $contact = $client_info ;
  • $profile = get_contact_profile($contact);
  • echo 'cpl'.$profile;
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case15
  • case "search people":
  • $sstatus = substr($client_info ,strpos($client_info , "*/s")+3,strpos($client_info , "*/k")-strpos($client_info , "*/s")-3);
  • $skeyword = substr($client_info ,strpos($client_info , "*/k")+3,strpos($client_info , "*/a")-strpos($client_info , "*/k")-3) ;
  • $sageh = substr($client_info ,strpos($client_info , "*/a")+3,strpos($client_info , "*/l")-strpos($client_info , "*/a")-3) ;
  • $slocation = substr($client_info ,strpos($client_info , "*/l")+3,strpos($client_info , "*/g")-strpos($client_info , "*/l")-3) ;
  • $sgender = substr($client_info ,strpos($client_info , "*/g")+3,strpos($client_info , "*/e")-strpos($client_info , "*/g")-3) ;
  • switch ($sageh) {
  • case "17":
  • $sagel = "0" ;
  • Break;
  • //--------------------case2
  • case "29":
  • $sagel = "18" ;
  • Break;
  • //--------------------case
  • case "44":
  • $sagel = "30" ;
  • Break;
  • //--------------------case
  • case "60":
  • $sagel = "45" ;
  • Break;
  • //--------------------case
  • case "61":
  • $sagel = "60" ;
  • Break;
  • //--------------------case
  • }
  • $sage = array ($sagel,$sageh);
  • people_search ($sstatus,$skeyword,$sage,$slocation,$sgender) ;
  • Break;
  • //---------------------------------------------------------------------------------- case16
  • case "get last status":
  • $user = $client_info ;
  • $status = check_user_status ($user) ;
  • echo 'uls'. $status ;
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case17
  • case "chat_message":
  • $username =substr($client_info ,strpos($client_info , "*/u")+3,strpos($client_info , "*/c")-strpos($client_info , "*/u")-3);
  • $contact =substr($client_info ,strpos($client_info , "*/c")+3,strpos($client_info , "*/m")-strpos($client_info , "*/c")-3);
  • $message =substr($client_info ,strpos($client_info , "*/m")+3,strpos($client_info , "*/s")-strpos($client_info , "*/m")-3);
  • //$fstyle = substr($client_info ,strpos($client_info , "*/s")+3,strpos($client_info , "*/o")-strpos($client_info , "*/s")-3);
  • // $fcolor substr($client_info ,strpos($client_info , "*/o")+3,strpos($client_info , "*/z")-strpos($client_info , "*/o")-3);
  • // $fsize substr($client_info ,strpos($client_info , "*/z")+3,strpos($client_info , "*/e")-strpos($client_info , "*/z")-3);
  • $font = substr($client_info ,strpos($client_info , "*/s"),strpos($client_info , "*/e")-strpos($client_info , "*/s"));
  • send_instant_message($contact,$message,$font,$username);
  • echo 'ims';
  • exit ;
  • Break;
  • //---------------------------------------------------------------------------------- case18
  • case "readchat_message":
  • $username = $client_info ;
  • read_chatmessage ($username);
  • Break;
  • //---------------------------------------------------------------------------------- case17
  • case "get_myalldata":
  • $username = $client_info ;
  • getall_Nfunction ($username) ;
  • Break;
  • //---------------------------------------------------------------------------------- case
  • Default;
  • echo 'not understand this request';
  • exit ;
  • }
  • function send_message ( $from,$to,$date,$subject,$message) {
  • $result = mysql_query ( "select userid_ from users_login where userid_ = '$to' ");
  • $row = mysql_fetch_array($result);
  • if ($row[0] == $to ) {
  • $table = $to . '_inbox' ;
  • mysql_query("Insert into $table ( from_ , date_ , subject_ , message_ , read_ ) Values ( '$from','$date','$subject','$message','1')");
  • echo 'message has been sent to: ' .$to;
  • exit ;
  • }else{
  • echo $to. ' not found ';
  • exit ;
  • }//--------------------------------end if
  • }
  • //----------------------------------------------------------------end function
  • function dir_myinbox ($user_table,$inbox_data){
  • $table = $user_table . '_inbox' ;
  • switch ($inbox_data) {
  • //-----------------------------case1
  • case "all new messages":
  • $result = Mysql_query("select * from $table where read_ = '1' ");
  • $Nmsg = mysql_num_rows($result) ;
  • if ($Nmsg == 0 ) {
  • return '0' ;
  • }else{
  • $result = get_allnew_messages ($user_table , $Nmsg,"all new messages");
  • return $result ;
  • }
  • Break;
  • //------------------------------case2
  • case "all messages":
  • $result = Mysql_query("select * from $table where read_ = '0' OR '1' ");
  • $Nmsg = mysql_num_rows($result) ;
  • get_allnew_messages ($user_table , $Nmsg,"all messages");
  • Break;
  • //------------------------------case3
  • case "all new messages count":
  • $result = Mysql_query("select * from $table where read_ = '1' ");
  • $Nmsg = mysql_num_rows($result) ;
  • return $Nmsg ;
  • Break;
  • }
  • }
  • //-----------------------------------------------------------------end function
  • function get_allnew_messages ($table_name , $data_count , $data ){
  • $table = $table_name . '_inbox';
  • switch ($data){
  • //-----------------------------case1
  • case "all new messages":
  • $result = mysql_query ( "select from_ , date_ , subject_ , message_ ,read_ from $table where read_ = '1' ");
  • Break;
  • //-----------------------------case2
  • case "all messages":
  • $result = mysql_query ( "select from_ , date_ , subject_ , message_ ,read_ from $table where read_ = '0' OR '1' ");
  • Break;
  • }
  • while ($row = mysql_fetch_array($result)) {
  • $all_data = $all_data."*/\f*".$row[0]."*/\d*".$row[1]."*/\s*".$row[2]."*/\m*".$row[3]."*/\a*".$row[4]."*/\e*"."*/\line" ;
  • } //end while
  • switch ($data){
  • //-----------------------------case1
  • case "all new messages":
  • return $data_count .$all_data ;
  • Break;
  • //-----------------------------case2
  • case "all messages":
  • echo 'amg'.$data_count .$all_data;
  • exit ;
  • Break;
  • }
  • }
  • //-----------------------------------------------------------------end function
  • function getallcontacts_from_my_list ($table){
  • addmy_timelogin ($table);
  • $table1 = $table . '_contact' ;
  • $result = Mysql_query("select * from $table1 ");
  • $Nmsg = mysql_num_rows($result) ;
  • while ($row = mysql_fetch_array($result)){
  • //$row[0]
  • $block_me = $row[2];
  • if ($block_me == 1){
  • $status = "offline";
  • }else{
  • $status = check_user_status ($row[0]);
  • }
  • $all_data = $all_data . "*/n". $row[0] ."*/b". $row[1]."*/s".$status."*/e"."*/line" ;
  • } //end while
  • $nmsgcount = dir_myinbox ($table,"all new messages count");
  • return $Nmsg. $all_data ;
  • } //-----------------------------------------------------------------end function
  • function check_user_status ($nickname){
  • $result = Mysql_query("select time_login ,status from users_status where nickname = '$nickname' ");
  • $row = mysql_fetch_array($result);
  • $time_login = array ( substr($row[0],0,2), substr($row[0],2,2), substr($row[0],4,2),substr($row[0],6,2),substr($row[0],8,2),substr($row[0],10,4));
  • //mktime($hour1,$minutes1,$seconds1,$month1,$day1,$year1)
  • $time_login = mktime($time_login[0],$time_login[1],$time_login[2],$time_login[3],$time_login[4],$time_login[5]) ;
  • $time_now = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")) ;
  • $differece = ($time_now - $time_login );
  • //10 seconds
  • if ($differece < 10) {
  • $status = $row[1];
  • }else{
  • $status ="offline";
  • }
  • return $status ;
  • } //-----------------------------------------------------------------end function
  • function add_a_contact($contact,$username) {
  • $result = Mysql_query("select * from users_status where nickname = '$contact' ");
  • $N = mysql_num_rows($result) ;
  • if ($N == 1){
  • $table1 = $username . '_contact' ;
  • $result = Mysql_query("select * from $table1 where contacts = '$contact' ");
  • $row = mysql_fetch_array($result);
  • $Nc = mysql_num_rows($result) ;
  • if ($Nc == 1 ){
  • return "2" ;
  • }else{
  • mysql_query("Insert into $table1 ( contacts,block ) Values ( '$contact','0')");
  • $table1 = $contact . '_contact' ;
  • $result = Mysql_query("select * from $table1 where contacts = '$username' ");
  • $Nc = mysql_num_rows($result) ;
  • if ($Nc <> 1){
  • mysql_query("Insert into $table1 ( contacts,block ) Values ( '$username','2')");
  • }
  • return "1"; }
  • }else{
  • return "0";
  • }
  • } //-----------------------------------------------------------------end function
  • function remove_a_contact ($contact,$username){
  • $table1 = $username . '_contact' ;
  • $result = Mysql_query("select * from $table1 where contacts = '$contact' ");
  • $N = mysql_num_rows($result) ;
  • if ($N == 1){
  • Mysql_query("delete from $table1 where contacts = '$contact'");
  • return "1" ;
  • }else{
  • return "0" ;
  • }
  • } //-----------------------------------------------------------------end function
  • function block_unblock_a_contact ($contact,$username){
  • $table1 = $username . '_contact' ;
  • $result = Mysql_query("select block , block_me from $table1 where contacts = '$contact' ");
  • $N = mysql_num_rows($result) ;
  • if ($N == 1){
  • $row = mysql_fetch_array($result);
  • if ($row[0] == 0){
  • Mysql_query("update $table1 set block = '1' where contacts = '$contact'");
  • $table1 = $contact . '_contact' ;
  • Mysql_query("update $table1 set block_me = '1' where contacts = '$username'");
  • return "1" ;
  • }else{
  • $table1 = $username . '_contact' ;
  • Mysql_query("update $table1 set block = '0' where contacts = '$contact'");
  • $table1 = $contact . '_contact' ;
  • Mysql_query("update $table1 set block_me = '0' where contacts = '$username'");
  • return "2" ;
  • }
  • }else{
  • return "3" ;
  • }
  • } //-----------------------------------------------------------------end function
  • function addmy_timelogin ($user_rows){
  • $timelogin = date("HismdY");
  • Mysql_query("update users_status set time_login = '$timelogin' where nickname = '$user_rows'");
  • }//-----------------------------------------------------------------end function
  • function change_status ($nickname , $status){
  • Mysql_query("update users_status set status = '$status' where nickname = '$nickname'");
  • }//-----------------------------------------------------------------end function
  • function get_contact_profile ($contact){
  • $result = mysql_query ( "select username_ , userage_ , userlocation_ , usergender_ , usermail_ from users_login where userid_ = '$contact' ");
  • $row = mysql_fetch_array($result);
  • $profile = "*/n".$row[0]."*/a".$row[1]."*/l".$row[2]."*/g".$row[3]."*/i".$row[4]."*/e" ;
  • return $profile ;
  • }//-----------------------------------------------------------------end function
  • function people_search ($sstatus,$keyword,$age,$location,$gender){
  • if ($keyword == ""){
  • if ($sage[0] == "60"){
  • //age over 60
  • $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_ from users_login where userlocation_ ='$location' and usergender_ = '$gender' and userage_ > $age[0] ");
  • }else{
  • $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_ from users_login where userlocation_ ='$location' and usergender_ = '$gender' and userage_ between $age[0] and $age[1] ");
  • }
  • }else{
  • if ($sage[0] == "60"){
  • //age over 60
  • $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_ from users_login where userid_ like '%$keyword%' and userlocation_ ='$location' and usergender_ = '$gender' and userage_ > $age[0] ");
  • }else{
  • $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_ from users_login where userid_ like '%$keyword%' and userlocation_ ='$location' and usergender_ = '$gender' and userage_ between $age[0] and $age[1] ");
  • }
  • }
  • $Nmsg = mysql_num_rows($result) ;
  • if ($Nmsg == 0){
  • echo 'cse'.$Nmsg ;
  • exit ;
  • }
  • while ($row = mysql_fetch_array($result)){
  • if ($sstatus == "1" ){
  • $cstatus = check_user_status ($row[0]);
  • if ($cstatus == "online" or $cstatus == "away" or $cstatus == "busy"){
  • $all_data = $all_data . "*/n". $row[0] ."*/a". $row[1] ."*/l". $row[2] ."*/g". $row[3] ."*/e" . "*/line" ;
  • }else{
  • $Nmsg = $Nmsg - 1 ;
  • }
  • }else{
  • $all_data = $all_data . "*/n". $row[0] ."*/a". $row[1] ."*/l". $row[2] ."*/g". $row[3] ."*/e" . "*/line" ;
  • }
  • } //end while
  • echo 'cse'.$Nmsg. $all_data ;
  • exit ;
  • }//-----------------------------------------------------------------end function
  • function send_instant_message($contact,$message,$font,$username){
  • $serverdate = date("H:i:s m/d/Y");
  • $table1 = $contact . '_chat' ;
  • mysql_query("Insert into $table1 ( contact_ , date_ , message_ , font_ ) Values ( '$username','$serverdate','$message','$font')");
  • } //-----------------------------------------------------------------end function
  • function read_chatmessage ($username){
  • $table1 = $username . '_chat' ;
  • $result = Mysql_query("select contact_ , date_ , message_ , font_ from $table1 ");
  • $N = mysql_num_rows($result) ;
  • if ($N > 0){
  • // Start
  • while ($row = mysql_fetch_array($result)){
  • Mysql_query("delete from $table1 where contact_ = '$row[0]' and message_ = '$row[2]'");
  • // */c contact */d date */m message */s font style */o font color */z font size */e */line
  • $all_data = $all_data . "*/a". $row[0] ."*/d". $row[1] ."*/m". $row[2] . $row[3] ."*/e" . "*/line" ;
  • } //end while
  • return $N.$all_data ;
  • }else{
  • return '0';
  • }
  • } //-----------------------------------------------------------------end function
  • function connect_to_database (){
  • $db = mysql_connect ( "localhost","root","") ;
  • mysql_select_db("safary_messenger",$db);
  • } //-----------------------------------------------------------------end function
  • function getall_Nfunction ($username){
  • //---username
  • addmy_timelogin ($username) ;
  • //---username
  • $nmsgcount = dir_myinbox ($username,"all new messages count");
  • $mycontactlist = getallcontacts_from_my_list ($username);
  • $mychatmsg = read_chatmessage ($username) ;
  • $data = '*/g' . $nmsgcount . "*/c" . $mycontactlist . '*/data2' . $mychatmsg ;
  • echo 'ald'.$data ;
  • exit ; //------------------------------------------------------------end function
  • }
  • function getall_Dlogin ($username){
  • //---username
  • addmy_timelogin ($username) ;
  • $mynewmsgdata = dir_myinbox ($username,"all new messages") ;
  • $mycontactlist = getallcontacts_from_my_list ($username);
  • $mylaststatus = check_user_status ($username) ;
  • return '*/u' . $mylaststatus . "*/c" . $mycontactlist . '*/data2' . $mynewmsgdata ;
  • } //-----------------------------------------------------------------end function
  • mysql_close($db );
  • ?>
//code de la WebService  fait par  PHP


//.....................................................START



<?php
// server folder : http://egypto.awardspace.com/server/connect.php
// Copyright © EGPTO.NET 2006. All rights reserved.
//By : Peter Gad Shehata
//email: Peter_Gad1@yahoo.com
//Phone: 0202-0125669727


$client_message = trim($client_message);
$client_info ;

//$ip = getenv ("REMOTE_ADDR");

 connect_to_database () ;


//$client_message = "login";
//$client_info = "id:half_angelpw:0123883491"   ;
//echo   $client_info."<br>" ;
//------------
switch ($client_message) {
//--------------------------------------------------------------------------------case1
//hi
        case  'hi' :
        echo  'ip:' . $ip ;
        Break;
//--------------------------------------------------------------------------------case2

       case  "login" :
       $userid     = trim(substr ($client_info,3,strpos($client_info , "pw")-3));
       $userpass =  substr ($client_info,strpos($client_info , "pw") +3 , strlen($client_info)-1);
//--------------------------------------------------------------------------------case3


$result = mysql_query ( "select userid_ , userpass_, username_  from users_login where userid_ = '$userid' ");

$row = mysql_fetch_array($result);
       if  ($userid == $row[0] and  $userpass == $row[1]){


        $result =  getall_Dlogin ($userid) ;
        echo "lit"."*/w".$row[2].$result ;
        exit ;
      }else{
 
        echo 'lif';
        exit ;
    
      }
       Break;
//---------------------------------------------------------------------------------case1

  case "send new message":

  $from        =  trim(substr ($client_info,strpos($client_info , "frm:")+4,strpos($client_info , "to:")-4));
  $to             =  trim(substr ($client_info,strpos($client_info , "to:")+3,strpos($client_info , "sub:")-strpos($client_info , "to:")-3));
  $subject    =  trim(substr ($client_info,strpos($client_info , "sub:")+4,strpos($client_info , "msg:")-strpos($client_info , "sub:")-4));
  $message  =  trim(substr ($client_info,strpos($client_info , "msg:")+4,strpos($client_info , "date:")-strpos($client_info , "msg:")-4));
  $date         =  trim(substr ($client_info,strpos($client_info , "date:")+5,strlen($client_info)-1));

 send_message ($from,$to,$date,$subject,$message);
  Break;
//----------------------------------------------------------------------------------cas5

  case "show all new messages":

$result = dir_myinbox ($client_info,"all new messages");
echo "nmg".$result ;
exit ;
Break;
//---------------------------------------------------------------------------------- case6

  case  "delete  message":

$m_from = trim(substr ($client_info,strpos($client_info , "frm:")+4,strpos($client_info , "date:")-4));
$m_date =  trim(substr ($client_info,strpos($client_info , "date:")+5,strpos($client_info , "tab:")-strpos($client_info , "date:")-5));
$m_table = trim(substr ($client_info,strpos($client_info , "tab:")+4,strlen($client_info)-1));


$table = $m_table . '_inbox';


mysql_query ( "delete from $table where from_ = '$m_from' and date_ = '$m_date'");

echo 'mgd';
exit ;
Break;
//---------------------------------------------------------------------------------- case7

  case  "show all message":

dir_myinbox ($client_info,"all messages");
Break;
//---------------------------------------------------------------------------------- case8

  case "show all contacts":

$c_table = $client_info ;

getallcontacts_from_my_list($c_table);
Break;
//---------------------------------------------------------------------------------- case9

  case "add a contact":

$contact = substr ($client_info ,0,strpos($client_info , "/u*")) ;
$username = substr ($client_info ,strpos($client_info , "/u*")+3,strpos($client_info , "/e*")-strpos($client_info , "/u*")-3);

$result = add_a_contact($contact,$username);
if ($result == "0") {
	
	echo 'car';
	exit ;
}elseif ($result == "1"){
	
	echo 'cad';
	exit ;
}else{
    
	echo 'cau';
}   exit ;
Break;
//---------------------------------------------------------------------------------- case10
   case "remove a contact":


$contact = substr ($client_info ,0,strpos($client_info , "/u*")) ;
$username = substr ($client_info ,strpos($client_info , "/u*")+3,strpos($client_info , "/e*")-strpos($client_info , "/u*")-3);
$result = remove_a_contact($contact,$username);

 if ($result == 1){
 	echo 'rct';
 	 exit ;
 }else{
 	echo 'rcf';
 }  exit ;
Break;
//---------------------------------------------------------------------------------- case11
   case "un/block a contact":


$contact = substr ($client_info ,0,strpos($client_info , "/u*")) ;
$username = substr ($client_info ,strpos($client_info , "/u*")+3,strpos($client_info , "/e*")-strpos($client_info , "/u*")-3);
$result = block_unblock_a_contact($contact,$username);

 if ($result == 1){
 	//block true
 	echo 'bct';
 	 exit ;
 }elseif ($result == 2){
    //unblock true
 	echo 'ubc';
 	exit ;
 }else{
 	echo 'bcf';
 	exit ;
 }
Break;
//---------------------------------------------------------------------------------- case12

   case  "read message":

$m_from = trim(substr ($client_info,strpos($client_info , "frm:")+4,strpos($client_info , "date:")-4));
$m_date =  trim(substr ($client_info,strpos($client_info , "date:")+5,strpos($client_info , "tab:")-strpos($client_info , "date:")-5));
$m_table = trim(substr ($client_info,strpos($client_info , "tab:")+4,strlen($client_info)-1));

$table = $m_table . '_inbox';


Mysql_query("update $table set read_ = '0' where from_ = '$m_from' and date_  ='$m_date'");

echo 'mgr';
 exit ;
Break;
 //---------------------------------------------------------------------------------- case13

   case "change my status":
 $nickname = substr ($client_info ,0,strpos($client_info , "/s*")) ;
 $status = substr ($client_info ,strpos($client_info , "/s*")+3,strpos($client_info , "/e*")-strpos($client_info , "/s*")-3);
 change_status($nickname,$status);
 echo 'usg';
 exit ;
 Break;
  //---------------------------------------------------------------------------------- case14

   case "get contact profile":
 $contact = $client_info ;

 $profile = get_contact_profile($contact);
 echo 'cpl'.$profile;
  exit ;
 Break;
 //---------------------------------------------------------------------------------- case15
  case "search people":
 
$sstatus = substr($client_info ,strpos($client_info , "*/s")+3,strpos($client_info , "*/k")-strpos($client_info , "*/s")-3);
$skeyword = substr($client_info ,strpos($client_info , "*/k")+3,strpos($client_info , "*/a")-strpos($client_info , "*/k")-3) ;
$sageh = substr($client_info ,strpos($client_info , "*/a")+3,strpos($client_info , "*/l")-strpos($client_info , "*/a")-3) ;
$slocation = substr($client_info ,strpos($client_info , "*/l")+3,strpos($client_info , "*/g")-strpos($client_info , "*/l")-3) ;
$sgender = substr($client_info ,strpos($client_info , "*/g")+3,strpos($client_info , "*/e")-strpos($client_info , "*/g")-3) ;
                  
                   switch ($sageh) {
                    case "17":
                    $sagel = "0" ;
                    Break;
                    //--------------------case2
                     case "29":
                    $sagel = "18" ;
                    Break;
                    //--------------------case
                        case "44":
                    $sagel = "30" ;
                    Break;
                    //--------------------case
                       case "60":
                    $sagel = "45" ;
                    Break;
                    //--------------------case
                      case "61":
                    $sagel = "60" ;
                    Break;
                    //--------------------case
                   }

$sage = array ($sagel,$sageh);

 people_search ($sstatus,$skeyword,$sage,$slocation,$sgender) ;

 Break;
//---------------------------------------------------------------------------------- case16

   case "get last status":
 $user = $client_info ;

 $status = check_user_status ($user) ;
  echo 'uls'. $status ;
  exit ;
 Break;
  //---------------------------------------------------------------------------------- case17
 
     case "chat_message":

  $username =substr($client_info ,strpos($client_info , "*/u")+3,strpos($client_info , "*/c")-strpos($client_info , "*/u")-3);
  $contact =substr($client_info ,strpos($client_info , "*/c")+3,strpos($client_info , "*/m")-strpos($client_info , "*/c")-3);
  $message =substr($client_info ,strpos($client_info , "*/m")+3,strpos($client_info , "*/s")-strpos($client_info , "*/m")-3);
  //$fstyle  = substr($client_info ,strpos($client_info , "*/s")+3,strpos($client_info , "*/o")-strpos($client_info , "*/s")-3);
 // $fcolor substr($client_info ,strpos($client_info , "*/o")+3,strpos($client_info , "*/z")-strpos($client_info , "*/o")-3);
 // $fsize substr($client_info ,strpos($client_info , "*/z")+3,strpos($client_info , "*/e")-strpos($client_info , "*/z")-3);
  $font = substr($client_info ,strpos($client_info , "*/s"),strpos($client_info , "*/e")-strpos($client_info , "*/s"));


   send_instant_message($contact,$message,$font,$username);
   echo 'ims';
   exit ;
 Break;
 //---------------------------------------------------------------------------------- case18

 case "readchat_message":
 $username = $client_info ;
 read_chatmessage ($username);

 Break;
  //---------------------------------------------------------------------------------- case17
   
    case "get_myalldata":
 $username = $client_info ;
  getall_Nfunction ($username) ;
 Break;
  //---------------------------------------------------------------------------------- case
Default;
 echo 'not understand this request';
 exit ;
}

function send_message ( $from,$to,$date,$subject,$message) {


$result = mysql_query ( "select userid_  from users_login where userid_  = '$to' ");

$row = mysql_fetch_array($result);

if ($row[0]  ==  $to ) {


$table = $to . '_inbox' ;
mysql_query("Insert into $table ( from_ , date_ , subject_ , message_ , read_ ) Values ( '$from','$date','$subject','$message','1')");
echo 'message has been sent  to: ' .$to;
exit ;
}else{

echo  $to. ' not found ';
exit ;
}//--------------------------------end if

}
//----------------------------------------------------------------end function

function dir_myinbox ($user_table,$inbox_data){


$table = $user_table . '_inbox' ;

switch ($inbox_data) {
//-----------------------------case1
   case "all new messages":


$result = Mysql_query("select *  from $table where read_ = '1' ");
$Nmsg = mysql_num_rows($result) ;
if ($Nmsg == 0 ) {
return '0' ;
}else{
$result = get_allnew_messages ($user_table , $Nmsg,"all new messages");
return $result ;
}
Break;
//------------------------------case2
   case "all messages":

$result = Mysql_query("select *  from $table where read_ = '0' OR '1' ");
$Nmsg = mysql_num_rows($result) ;
get_allnew_messages ($user_table , $Nmsg,"all messages");
Break;
//------------------------------case3
   case "all new messages count":

$result = Mysql_query("select *  from $table where read_ = '1' ");
$Nmsg = mysql_num_rows($result) ;
return $Nmsg ;
Break;
}
}
//-----------------------------------------------------------------end function

function  get_allnew_messages  ($table_name , $data_count , $data ){



$table = $table_name . '_inbox';
switch ($data){
//-----------------------------case1
case "all new messages":


$result = mysql_query ( "select  from_ , date_  , subject_ , message_ ,read_ from $table where read_ = '1' ");
Break;
//-----------------------------case2
case "all messages":

$result = mysql_query ( "select  from_ , date_  , subject_ , message_ ,read_ from $table where read_ = '0' OR '1' ");
Break;
}

                       while ($row = mysql_fetch_array($result)) {
                      
                      $all_data = $all_data."*/\f*".$row[0]."*/\d*".$row[1]."*/\s*".$row[2]."*/\m*".$row[3]."*/\a*".$row[4]."*/\e*"."*/\line" ;

                     }  //end while

  
 switch ($data){
//-----------------------------case1
case "all new messages":
return  $data_count .$all_data ;
Break;
//-----------------------------case2
case "all messages":
echo 'amg'.$data_count .$all_data;
exit ;
Break;
}



}
//-----------------------------------------------------------------end function

 function getallcontacts_from_my_list ($table){

  
  addmy_timelogin ($table);
   
  $table1 = $table . '_contact'  ;
 
  $result = Mysql_query("select *  from $table1 ");
 
  $Nmsg = mysql_num_rows($result) ;
  

                       while ($row = mysql_fetch_array($result)){
                       
                       	//$row[0]
                       	
                       	$block_me = $row[2];
                       	if ($block_me == 1){
                        $status = "offline";
                        }else{
                        $status = check_user_status ($row[0]);
                        }
                     
                       $all_data = $all_data . "*/n".  $row[0]  ."*/b". $row[1]."*/s".$status."*/e"."*/line"  ;

                       }  //end while
  
  $nmsgcount = dir_myinbox ($table,"all new messages count");
  

  return $Nmsg. $all_data ;

 } //-----------------------------------------------------------------end function
  
 function check_user_status ($nickname){


 $result = Mysql_query("select time_login ,status  from users_status  where nickname = '$nickname' ");
 $row = mysql_fetch_array($result);
 
 $time_login = array ( substr($row[0],0,2), substr($row[0],2,2), substr($row[0],4,2),substr($row[0],6,2),substr($row[0],8,2),substr($row[0],10,4));
   
                        //mktime($hour1,$minutes1,$seconds1,$month1,$day1,$year1)
                        
                        $time_login = mktime($time_login[0],$time_login[1],$time_login[2],$time_login[3],$time_login[4],$time_login[5]) ;
                        
                        $time_now =  mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")) ;
                        
                        $differece = ($time_now - $time_login );
                        
                       
                        //10 seconds
                      if ($differece < 10) {
                        	$status = $row[1];
                        }else{
                            $status ="offline";
                        }

 
 return  $status ;
 } //-----------------------------------------------------------------end function
   
 function add_a_contact($contact,$username) {
 

 
 
  $result = Mysql_query("select *  from users_status where nickname = '$contact' ");
  
  $N = mysql_num_rows($result) ;
  
  if ($N == 1){
     
  $table1 = $username . '_contact' ;
 
  $result = Mysql_query("select *  from $table1 where contacts = '$contact' ");
  $row = mysql_fetch_array($result);
 
  $Nc = mysql_num_rows($result) ;
  
  
  if ($Nc == 1  ){
   return "2" ;
  }else{
 
 mysql_query("Insert into $table1 ( contacts,block ) Values ( '$contact','0')");
 
 
       
  $table1 = $contact . '_contact' ;
 $result = Mysql_query("select *  from  $table1 where contacts = '$username' ");

  $Nc = mysql_num_rows($result) ;

          if ($Nc <> 1){
          mysql_query("Insert into  $table1 ( contacts,block ) Values ( '$username','2')");
         }
 return "1"; }
 }else{
 
 return "0";
 }
 }  //-----------------------------------------------------------------end function
 
 function remove_a_contact ($contact,$username){

 
 
        
  $table1 = $username . '_contact' ;
  $result = Mysql_query("select *  from $table1 where contacts = '$contact' ");
  
  $N = mysql_num_rows($result) ;
  
  if ($N == 1){
  
   Mysql_query("delete from $table1 where contacts = '$contact'");
   return "1" ;
  }else{
   return "0" ;
  }
 }  //-----------------------------------------------------------------end function
 function block_unblock_a_contact ($contact,$username){



          
  $table1 = $username . '_contact' ;
  $result = Mysql_query("select block , block_me from $table1  where contacts = '$contact' ");
  
  $N = mysql_num_rows($result) ;
  
  if ($N == 1){
  
  $row = mysql_fetch_array($result);
   if ($row[0] == 0){
   
   Mysql_query("update $table1 set block = '1' where contacts = '$contact'");
  
           
  $table1 = $contact . '_contact' ;
   Mysql_query("update $table1 set block_me = '1' where contacts = '$username'");

   return "1" ;
   }else{
  
  $table1 = $username . '_contact' ;
   Mysql_query("update $table1 set block = '0' where contacts = '$contact'");
 
   $table1 = $contact . '_contact' ;
    Mysql_query("update $table1 set block_me = '0' where contacts = '$username'");
   return "2" ;
   }
  }else{
   return "3" ;
  }
 } //-----------------------------------------------------------------end function
 
 function addmy_timelogin ($user_rows){
 
 $timelogin = date("HismdY");

 
 Mysql_query("update users_status   set time_login = '$timelogin' where nickname = '$user_rows'");

 }//-----------------------------------------------------------------end function

 function change_status ($nickname , $status){


 Mysql_query("update users_status   set status = '$status' where nickname = '$nickname'");
 }//-----------------------------------------------------------------end function


 function get_contact_profile ($contact){

 
 $result = mysql_query ( "select username_ , userage_ , userlocation_ , usergender_ , usermail_ from users_login where userid_  = '$contact' ");

 $row = mysql_fetch_array($result);
 $profile = "*/n".$row[0]."*/a".$row[1]."*/l".$row[2]."*/g".$row[3]."*/i".$row[4]."*/e" ;
 return $profile ;
 }//-----------------------------------------------------------------end function

 function people_search ($sstatus,$keyword,$age,$location,$gender){



 if ($keyword == ""){
 

 if ($sage[0] == "60"){
 //age over 60
  $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_   from users_login where userlocation_ ='$location' and  usergender_ = '$gender' and userage_  > $age[0] ");

  }else{

  $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_   from users_login where userlocation_ ='$location' and  usergender_ = '$gender' and userage_  between $age[0] and $age[1] ");

  }
 }else{
 
  if ($sage[0] == "60"){
   //age over 60
 $result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_   from users_login where userid_  like '%$keyword%' and  userlocation_ ='$location' and  usergender_ = '$gender' and userage_  > $age[0]  ");

 }else{
 	$result = mysql_query ( "select userid_ , userage_ , userlocation_ , usergender_   from users_login where userid_  like '%$keyword%' and  userlocation_ ='$location' and  usergender_ = '$gender' and userage_  between $age[0] and $age[1] ");

 }
 }



  $Nmsg = mysql_num_rows($result) ;



  if ($Nmsg == 0){
   echo  'cse'.$Nmsg ;
   exit ;
   }

   

                       while ($row = mysql_fetch_array($result)){
                    
                       if ($sstatus == "1" ){
                     
                       $cstatus = check_user_status ($row[0]);
                
                       if ($cstatus == "online" or $cstatus == "away" or $cstatus == "busy"){

                          $all_data = $all_data . "*/n".  $row[0]  ."*/a". $row[1] ."*/l". $row[2] ."*/g". $row[3] ."*/e" . "*/line"  ;
                        }else{
         
                         $Nmsg = $Nmsg - 1 ;
                        }
                       }else{
            
                       $all_data = $all_data . "*/n".  $row[0]  ."*/a". $row[1] ."*/l". $row[2] ."*/g". $row[3] ."*/e" . "*/line"  ;
                       }
                       }  //end while

  echo  'cse'.$Nmsg. $all_data ;
  exit ;
 }//-----------------------------------------------------------------end function


 function  send_instant_message($contact,$message,$font,$username){


 $serverdate = date("H:i:s m/d/Y");


   $table1 = $contact . '_chat' ;
 mysql_query("Insert into $table1 ( contact_ , date_ , message_ , font_ ) Values ( '$username','$serverdate','$message','$font')");


 } //-----------------------------------------------------------------end function
 
 function  read_chatmessage ($username){


 
   $table1 = $username . '_chat' ;
 $result = Mysql_query("select contact_ , date_ , message_ , font_   from $table1 ");
 $N = mysql_num_rows($result) ;
 
 if ($N > 0){
 // Start

                        while ($row = mysql_fetch_array($result)){
                     
                       Mysql_query("delete from $table1 where contact_  = '$row[0]' and message_ = '$row[2]'");
                      
                       //   */c  contact  */d  date */m message */s  font style */o font color */z font size */e  */line
                        $all_data = $all_data . "*/a".  $row[0]  ."*/d". $row[1] ."*/m". $row[2] . $row[3] ."*/e" . "*/line"  ;
                       }  //end while

  return $N.$all_data ;

 }else{
 	return '0';

 	}

 } //-----------------------------------------------------------------end function
 
 function connect_to_database (){
 
 $db = mysql_connect ( "localhost","root","") ;
 
 mysql_select_db("safary_messenger",$db);

 } //-----------------------------------------------------------------end function


 function  getall_Nfunction ($username){

 //---username
 addmy_timelogin ($username) ;
 
 //---username
 $nmsgcount = dir_myinbox ($username,"all new messages count");

 $mycontactlist =  getallcontacts_from_my_list ($username);

 $mychatmsg =  read_chatmessage ($username) ;

 
 $data = '*/g' . $nmsgcount . "*/c" . $mycontactlist . '*/data2' . $mychatmsg ;

 echo 'ald'.$data ;
 exit ; //------------------------------------------------------------end function
 }

   
 function getall_Dlogin ($username){

 //---username
 addmy_timelogin ($username) ;
 
 
 $mynewmsgdata =  dir_myinbox ($username,"all new messages") ;
 
 $mycontactlist =  getallcontacts_from_my_list ($username);

 $mylaststatus = check_user_status ($username) ;

 return  '*/u' . $mylaststatus . "*/c" . $mycontactlist . '*/data2' . $mynewmsgdata ;

 } //-----------------------------------------------------------------end function


 mysql_close($db );
?>








Conclusion

vous pouvez trouver  aussi  le source code sur cette link

http://egypto.awardspace.com/services/uploadfiles/files/Messenger.rar
 

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !