Created
September 26, 2014 20:05
-
-
Save josemoralesp/75963ae68b99cfd4aeca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function connect() { | |
var $user = 'admin'; | |
var $password = 'admin'; | |
var $dbname = 'db_name'; | |
var $server_url = 'http://localhost:8069/xmlrpc/'; | |
if(isset($_COOKIE["user_id"]) == true) { | |
if($_COOKIE["user_id"]>0) { | |
return $_COOKIE["user_id"]; | |
} | |
} | |
$sock = new xmlrpc_client($server_url.'common'); | |
$msg = new xmlrpcmsg('login'); | |
$msg->addParam(new xmlrpcval($dbname, "string")); | |
$msg->addParam(new xmlrpcval($user, "string")); | |
$msg->addParam(new xmlrpcval($password, "string")); | |
$resp = $sock->send($msg); | |
$val = $resp->value(); | |
$id = $val->scalarval(); | |
setcookie("user_id",$id,time()+3600); | |
if($id > 0) { | |
return $id; | |
}else{ | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment