Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET PHP
session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'fb');
define('DB_PASSWORD', 'fb');
define('DB_DATABASE', 'fb');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
 
if ($_GET['action'] == "chatheartbeat") { chatHeartbeat(); }
if ($_GET['action'] == "sendchat") { sendChat(); }
if ($_GET['action'] == "closechat") { closeChat(); }
if ($_GET['action'] == "startchatsession") { startChatSession(); }
if ($_GET['action'] == "chatname") { chatName(); }
 
if (!isset($_SESSION['chatHistory'])) {
    $_SESSION['chatHistory'] = array();
}
 
if (!isset($_SESSION['openChatBoxes'])) {
    $_SESSION['openChatBoxes'] = array();
}
 
function chatHeartbeat() {
    $sql = "select users.username,chat.from,chat.message,chat.to,chat.id,chat.sent,chat.recd from chat,users where (chat.to = '".mysql_real_escape_string($_SESSION['chatuser'])."' AND recd = 0) and chat.from=users.uid order by id ASC";
 
    $query = mysql_query($sql);
    $items = '';
 
    $chatBoxes = array();
 
    while ($chat = mysql_fetch_array($query)) {
 
        if (!isset($_SESSION['openChatBoxes'][$chat['from']]) && isset($_SESSION['chatHistory'][$chat['from']])) {
            $items = $_SESSION['chatHistory'][$chat['from']];
        }
 
        $chat['message'] = sanitize($chat['message']);
 
        $items .= &lt;&lt;<eod>
                       {
            "s": "0",
            "u": "{$chat['username']}",
            "f": "{$chat['from']}",
            "m": "{$chat['message']}"
       },
EOD;
 
    if (!isset($_SESSION['chatHistory'][$chat['from']])) {
        $_SESSION['chatHistory'][$chat['from']] = '';
    }
 
    $_SESSION['chatHistory'][$chat['from']] .= &lt;&lt;<eod>
                           {
            "s": "0",
            "u": "{$chat['username']}",
            "f": "{$chat['from']}",
            "m": "{$chat['message']}"
       },
EOD;
 
        unset($_SESSION['tsChatBoxes'][$chat['from']]);
        $_SESSION['openChatBoxes'][$chat['from']] = $chat['sent'];
    }
 
    if (!empty($_SESSION['openChatBoxes'])) {
    foreach ($_SESSION['openChatBoxes'] as $chatbox =&gt; $time) {
        if (!isset($_SESSION['tsChatBoxes'][$chatbox])) {
            $now = time()-strtotime($time);
            $time = date('g:iA M dS', strtotime($time));
 
            $message = "Sent at $time";
            if ($now &gt; 180) {
                $items .= &lt;&lt;<eod>
{
"s": "2",
"f": "$chatbox",
"m": "{$message}"
},
EOD;
 
    if (!isset($_SESSION['chatHistory'][$chatbox])) {
        $_SESSION['chatHistory'][$chatbox] = '';
    }
 
    $_SESSION['chatHistory'][$chatbox] .= &lt;&lt;<eod>
        {
"s": "2",
"f": "$chatbox",
"m": "{$message}"
},
EOD;
            $_SESSION['tsChatBoxes'][$chatbox] = 1;
        }
        }
    }
}
 
    $sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($_SESSION['chatuser'])."' and recd = 0";
    $query = mysql_query($sql);
 
    if ($items != '') {
        $items = substr($items, 0, -1);
    }
header('Content-type: application/json');
?&gt;
{
        "items": [
            <?php echo $items;??>
 

[edit]Code block added - OriginalGriff[/edit]
Posted 5-Nov-12 20:19pm
Edited 5-Nov-12 20:36pm
v2
Comments
Sergey Alexandrovich Kryukov at 6-Nov-12 2:36am
   
What makes you thinking that "conversion" even makes sense? These programming technologies are very different. And you did not even explain what you want to achieve. It does not look a productive approach.
 
If you need to learn ASP.NET, try to do it, ask questions. And ultimately, implement what you need.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

No.
We are not here to take your code, convert it (without knowing what it does, or is supposed to do), test it, debug it, and make it work.
 
In other words, do your work for you.
 
Try for yourself. If you get a specific problem, then feel free to come back and ask about it. But we will not do your whole task for you!
  Permalink  
Comments
Muhammd Faris at 6-Nov-12 4:11am
   
i want to buid a chat like facebook ...i know only asp.net , when i check i see only php codes..

if you know code for chatting like facebook..please send me the link.
OriginalGriff at 6-Nov-12 4:25am
   
Strange - a very quick google gave me this: http://www.codeproject.com/Articles/33817/Build-a-Web-based-Chat-using-ASP-NET-Ajax
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

!!!!!!!!LOL!!!!!!!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 853
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 166
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100