Please explain me this logic

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
th.jayakumar
Forum Newbie
Posts: 6
Joined: Mon Mar 22, 2010 6:04 am

Please explain me this logic

Post by th.jayakumar »

CAn any one please explain me this logic
am learning PHP


function process {
$from = $_SESSION['username'];
$to = $_POST['to'];
$message = $_POST['message'];

$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());

$messagesan = sanitize($message);

if (!isset($_SESSION['chatHistory'][$_POST['to']])) {
$_SESSION['chatHistory'][$_POST['to']] = '';
}

$_SESSION['chatHistory'][$_POST['to']] .= <<<EOD
{
"s": "1",
"f": "{$to}",
"m": "{$messagesan}"
},
EOD;


unset($_SESSION['tsChatBoxes'][$_POST['to']]);

$sql = "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())";
$query = mysql_query($sql);
echo "1";
exit(0);
}

what is the meaning for this statement

$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());

in which variable we are storing the POST data

what is meaning for this

!isset($_SESSION['chatHistory'][$_POST['to']])

wat this statement actually does
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Please explain me this logic

Post by manohoo »

$_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time());
a time stamp is stored in a session array
in which variable we are storing the POST data
$to = $_POST['to'];
$message = $_POST['message'];
what is meaning for this
!isset($_SESSION['chatHistory'][$_POST['to']])
the above code is checking for the existence of an array element

I recommend that you check the contents of $_SESSION, as it will answer some of your questions:

Code: Select all

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
Post Reply