Page 1 of 1

Please explain me this logic

Posted: Mon Mar 22, 2010 9:13 am
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

Re: Please explain me this logic

Posted: Mon Mar 22, 2010 11:50 am
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>';