I am just trying to design a chat application which allows cross domain chat between users of two domains, that is, allows to create chat rooms and chat. So, I was suggested to use curl and ajax. But I don't know how I could do it and also don't know much about curl. I know it is used to transfer files/data between domains using HTTP, various protocols. But I have question, how can the messages be transferred among domains with login check. I found the following code snippet when i googled, but couldn't understand it. Does CURL_SSL_VERIFYPEER do the verification of domains and redirect only authorized ones? And please explain me what curl_setopt($ch, CURLOPT_POSTFIELDS,"user_name=$user_name&cmd=$send_cmd&domain=$my_domain");
// code snippet //
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_FAILONERROR,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"user_name=$user_name&cmd=$send_cmd&domain=$my_domain");
$res = curl_exec($ch);
curl_close($ch);
2) My second question is i want to use session variables here and so using $_SESSION. I came to know that whenever we are using session variables in a page, we need to use session_start(); but why is it working even if I didn't use session_start() at the top? I just gave the following code
// code //
require_once 'db_connect.php';
if (isset($_SESSION ['user_id']) && !empty($_SESSION ['user_id']))
{
echo '<p align="center">Hi, '.$_SESSION ['first_name'].'</p>';
$u_name = $_SESSION['user_name'];
include 'home.php';
}
else
{
//some stmt
}
/*******home.php file ****/
<?php
require_once 'dbconnect.php';
$_SESSION['username'] = $u_name;
?>
In the above I didn't use any session_start() and also I didn't get variables using GET or POST but even then how is $u_name passed to home.php page?
3) and what does the following statement do?
echo '<link rel="stylesheet" type="text/css" href="bck_ground.css" />';
Thanks
I'm not sure what is " enables users of two domains to create chat rooms and chat" means exactly, but if you need cross-domain ajax requests, check Access-Control-Allow-Origin
header. It's supported by all modern browsers.
If you're still need to support older browsers, you can do proxy-ing of ajax-request from one domain to another. And as for me, you don't need PHP at all - you can put proxy rules into .htaccess
for example.