Authorization of CURL php
-
I've got two websites and I want to a simultaneous authorization,
i.e.: When a person is authorised on site 1, the connection via CURL to site 2 with the same data begins at the time of checking the data.
I've already done it through CURL. But when I do clips on the site that authorised through CURL, the copying goes missing. ♪ I understand that because of the cukes... Now they're just recording into the cookies.txt file. ♪ ♪
Can they be transferred to the browser somehow?
Oh, I'm just studying php. So would you like to know if my idea was logical and, if so, how to decide?
here's the copying code.
<?php
// функции для cms
class work_init_moduls
{function __construct()
{}
static public function get_num_modul($name_modul)
{
global $list_modules;
$num_modul = 0;if ( !empty($list_modules[$name_modul]) ) { $num_modul = $list_modules[$name_modul][5]; } return ($num_modul); }
static public function get_name_modul($num_modul)
{
global $list_modules;
$name_modul = 0;foreach ($list_modules as $one_modul ) { if ( $one_modul[5] == $num_modul ) $name_modul = $one_modul[0]; } return ($name_modul); }
}
function forming_signature_email()
{
global $masConfig;
$t = trim($masConfig["EMAIL_ADMIN_SIGNATURE"]);if ( $t ) $t = "<br><br>".$t;
return ($t);
}// класс для работы с сессией пользователя на сайте
class session_auth_user
{function __construct()
{}
static public function set_session($data_user, $on_memory)
{// добаляем в сессию данные $_SESSION["time_avt"]=$GLOBALS["timeGlobal"]; $_SESSION["id_user"] = $data_user["id_user"]; $_SESSION["name_user_avt"] = $data_user["name_user"]; $_SESSION["passw_user_avt"] = $data_user["password_user"]; $_SESSION["email_user_avt"] = $data_user["email_user"]; $_SESSION["access_admin_avt"] = $data_user["access_admin"]; $_SESSION["s_data_authorize_user"] = $data_user; // добаляем в глобальные переменные данные $GLOBALS["user_to_site"] = true; $GLOBALS["name_user_to_site"] = $data_user["name_user"]; $GLOBALS["passw_user_to_site"] = $data_user["password_user"]; $GLOBALS["id_user_to_site"] = $data_user["id_user"]; $GLOBALS["email_user_to_site"] = $data_user["email_user"]; $GLOBALS["access_admin"] = $data_user["access_admin"]; $GLOBALS["data_authorize_user"] = $data_user; if ( $on_memory ) { self::set_cookie_memory($data_user); } }
static public function check_auth_user()
{$GLOBALS["user_avtoriz"]=true;//авторизация на сайте включена (глобальная переменная для других модулей) $check_access = 0; $num_user = 0; $time_session = 0; $data_user = false; $time_tek=$GLOBALS["timeGlobal"]; $clear_session = false; $on_memory_session = false; if ( isset($_SESSION["id_user"]) && isset($_SESSION["time_avt"]) && is_numeric($_SESSION["id_user"]) && is_numeric($_SESSION["time_avt"]) ) { //сессия определена $time_session = $_SESSION['time_avt']; $num_user = $_SESSION["id_user"]; $data_user = self::check_num_user($num_user); if ( !$data_user ) { $num_user = 0; $time_session = 0; $data_user = false; } } if ( $num_user > 0 ) { if ( ( $time_tek-$time_session ) > TIME_SESSION_AVTORIZ ) { //время сессии вышло $check_access = 0; $clear_session = true; $num_user = 0; $data_user = false; $time_session = 0; } } if ( $num_user == 0 ) { $data_user_ck = self::check_user_cookie_memory(); if ( $data_user_ck != false ) { $data_user = $data_user_ck; //self::set_session($data_user,true); $num_user = $data_user["id_user"]; $time_session = time(); $clear_session = false; $on_memory_session = true; self::save_time_authoriz_user("",$num_user); } } if ( $clear_session ) { self::clear_session(false);//удаляем сессию } elseif ( $num_user && $time_session && $data_user ) { self::set_session($data_user,$on_memory_session); } return ( $num_user > 0 ? $data_user : false ); }
static public function check_num_user($id_user)
{
$data_user=false;$db_query="select * from ".DB_PREF."users " ." where id_user='".codeText($id_user)."' " //."and BINARY password_user='".md5($password_user)."' " ." and ( access_user='on' or access_admin = 'sadmin' ) "; list($kolvo,$data_user)=db_work::query_select_one_assoc($db_query); if ($kolvo != 1) { $data_user = false; } return ($data_user); }
static public function check_user_cookie_memory()
{
$data = false;
if ( isset($_COOKIE["memoryauth"]) )
{
$mas_data = explode(":",base64_decode($_COOKIE["memoryauth"]));
$error = false;
if ( sizeof($mas_data) == 2 && $mas_data[0] && $mas_data[1] && is_numeric($mas_data[0]) )
{
$data_user_db = self::check_num_user($mas_data[0]);
if ( $data_user_db )
{
$sk = md5("luHTUge7djyYT883Ytu06hTGHIdbvmBJGKjg75fJGf5t" . md5($data_user_db["password_user"]."g39dkjgkd93kdfj39dkjf83jdkeJKHGkj7y"));
if ( $sk == $mas_data[1] )
{
$data = $data_user_db;
}
else
{
$error = true;
}
}
else
{
$error = true;
}
}
else
{
$error = true;
}if ( $error ) { //удаляем куку self::set_cookie_memory(false); } } return ($data); }
static public function clear_session($delete_cookie_memory = true)
{
if (isset($_SESSION['id_user']))
{
//session_destroy();
unset($_SESSION['time_avt']);
unset($_SESSION['id_user']);} if ( $delete_cookie_memory ) { self::set_cookie_memory(false); } }
static public function set_cookie_memory($data_user)
{
// если $data_user -> false , то удаляем куку
$time_c = time()+360024100;
if ( $data_user == false )
{
$v = "";
$time_c = 1000;
}
else
$v = base64_encode($data_user["id_user"].":".md5("luHTUge7djyYT883Ytu06hTGHIdbvmBJGKjg75fJGf5t" . md5($data_user["password_user"]."g39dkjgkd93kdfj39dkjf83jdkeJKHGkj7y")));setcookie("memoryauth",$v,$time_c,"/"); }
static public function init_authoriz_user_sc()
{$GLOBALS["user_avtoriz"]=false;//авторизация пользователей на сайте (false - нет, true - да) $GLOBALS["user_to_site"]=false;//авторизован ли пользователь на сайте (false - нет, true - да) $GLOBALS["name_user_to_site"]="";//имя авторизованного пользователя $GLOBALS["passw_user_to_site"]="";//зачение md5(пароль пользователя) $GLOBALS["id_user_to_site"]=-1;//уникальный номер пользователя - поле id_user таблицы users $GLOBALS["email_user_to_site"]="";//e-mail пользователя авторизованного на сайте $GLOBALS["access_admin"] = ""; $GLOBALS["data_authorize_user"] = false; self::check_auth_user(); }
static public function save_time_authoriz_user($name_user,$id_user = false)
{
$db_query="update ".DB_PREF."users set date_visit=".$GLOBALS["timeGlobal"]." where ".( $id_user ? " id_user = ".$id_user." " : " name_user='".$name_user."' ");
$q_result = db_work::query($db_query);
}}
code curl
<?php
$url = "http://www.sait.ru/registr/enter/";
$referer = "http://www.cat.hr00.ru/";
$user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
$post = "name_user=admin&password_user=123456sa&memory_authoriz=on&submit_avtoriz=Войти&control_avtoriz=send_avtoriz";
$header [] = "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, /;q=0.1";
$header [] = "Accept-Language: ru-RU,ru;q=0.9,en;q=0.8";
$header [] = "Accept-Charset: Windows-1251, utf-8, *;q=0.1";
$header [] = "Accept-Encoding: deflate, identity, *;q=0";$user_cookie = "cookies.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $user_cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $user_cookie);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close($ch);echo $result;
?>
-
curl isn't here at all.
after the authorisation of the first home user
<img src="http://domain2.com/setcookie.php?cookie=value" />
In the second home, implement the best
setcookie.php
type<?php if(isset($_GET['cookie'])){ setcookie("auth", $_GET['cookie'], time()+3600); }
Further teach the second site to identify the first site user under the cookie request; implementation depends on how the authorised users are stored on the first site.