I'm create a remote access using codeigniter curl library from here https://github.com/philsturgeon/codeigniter-curl , then using this code below to login, then I get good respons that I've logged in.
$this->load->library('curl');
$opt = array(
'COOKIEJAR' => 'curl_sess/cookie.txt',
'COOKIEFILE' => 'curl_sess/cookie.txt',
);
$array = array(
'email' => 'user#example.com',
'password' => 'somepassword'
);
echo $this->curl->simple_post('http://remoteweb.com/cek_login', $array, $opt);
Then I want to create another request that need logged in status, like :
$array = array();
echo $this->curl->simple_get('http://remoteweb.com/get_datadeposit', $array);
but I get nothing, because my login session at first request not brought in second request.How to achieve this or I missing something ... ?
Try
$this->load->library('curl');
$opt = array(
CURLOPT_COOKIEJAR => 'curl_sess/cookie.txt',
CURLOPT_RETURNTRANSFER => true
);
$array = array(
'email' => 'user#example.com',
'password' => 'somepassword'
);
echo $this->curl->simple_post('http://remoteweb.com/cek_login', $array, $opt);
Related
<?php
$client = new SoapClient("http://localhost/suiteCRM/service/v2/soap.php?wsdl");
$response = $client->__soapCall("login", array(
"user_auth" =>
array(
'user_name' => 'admin',
'password' => md5('223311'),
'version' => "0.1",
),
"application_name"=>""
)
);
$session_id=$response->id;
echo"Session ID".$session_id;
?>
while i connecting it gives 404 error i need solution how to store form values to suitecrm
You should use rest rather than SOAP.
ideally, your URL will be.
http://localhost/suiteCRM/service/v4/rest.php
I'm hoping someone can help me out. I inherited some code that I have no idea how it works and now that it broke I have to fix it.
I am running PHP 5.5.38 on Windows server 2012 and IIS 8.5. I have finally discovered that the php code is using httprequest which doesn't exist anymore in my version of php and with windows. How would I convert the following to use curl code, if it is even possible?
$http = new HttpRequest('https://my.securelink.com/external/readi/ssoRequest', HttpRequest::METH_POST);
$http->addHeaders(
array(
'READI_AccessKey' => $accesskey,
'READI_Timestamp' => $timestamp,
'READI_RequestSignature' => $mac
)
);
$http->addPostFields(
array(
'READIUsername' => 'myusername',
'LastName' => $_GET["lastn"],
'FirstName' => $_GET["firstn"],
'Email' => $_GET["em"],
'ForceNewAssessment' => false,
'InternalID' => $_GET["userid"],
'IncludeSettings' => ''
)
);
//Optional Post Field: 'READIUserID' => 'xxxxxx'
$response = $http->send()->getBody();
echo "<h3>===== Response ===== </h3>";
echo "<pre>";
echo $response;
echo "</pre>";
$arr = xml2array($response);
$rtn_status = getvaluebypath($arr,'sso/status');
$rtn_timestamp = getvaluebypath($arr,'sso/timestamp');
if($rtn_status == "success") {
$redirectURL = getvaluebypath($arr,'sso/redirectUrl');
echo "<h3>===== Access Link ===== </h3>";
echo "" . $redirectURL . "";
header( "Location: $redirectURL");
}
You can try adding the HttpRequest class as guyver4mk suggested (the link from Jiri Hrazdil's comment) if you don't want to change the whole code.
But since you asked how to convert the existing to cURL, try this:
$header = [
'READI_AccessKey: '.$accesskey,
'READI_Timestamp: '.$timestamp,
'READI_RequestSignature: '.$mac
];
$post = [
'READIUsername' => 'myusername',
'LastName' => $_GET["lastn"],
'FirstName' => $_GET["firstn"],
'Email' => $_GET["em"],
'ForceNewAssessment' => false,
'InternalID' => $_GET["userid"],
'IncludeSettings' => ''
];
$ch = curl_init();
$options = [
CURLOPT_URL => 'https://my.securelink.com/external/readi/ssoRequest',
CURLOPT_HTTPHEADER => $header,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $post,
CURLOPT_RETURNTRANSFER => 1
];
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if (!$response)
print_r(curl_error($ch));
curl_close($ch);
I am sending post requests in PHP to get a boolean value from my API (so it should return wither true or false)
This is the code I am using in the file for my API. The file is called users.php
if ($_POST['type'] == "authenticateMinecraft"){
$p = new dibdibs\post(
array(
'url' => 'https://authserver.mojang.com/authenticate',
'data' => array(
'agent' => array(
'name' => 'Minecraft',
'version' => 1
),
'username' => $_POST['username'],
'password' => $_POST['password'],
'clientToken' => "33225A179D9A4E1BDA73C012C1C3CBAB8BD00326883BDBEB6FA682482E40F68D"
)
)
);
$res = $p->json();
if (isset($res["selectedProfile"])){
echo("true");
}
else{
echo("false");
}
}
This is the code I am using to reference it (I am using a class which I have put on Pastebin to actually send the request).
$params = array(
'data' => array(
'type' => 'authenticateMinecraft',
'username' => $mcuname,
'password' => $mcpasswd
),
'url' => "api/users.php"
);
$c = new dibdibs\post($params);
$r = $c->http();
var_dump($r);
Whenever I use the .php fule extension when defining url, the whole PHP code of the API page is returned, but when I remove the extension, only true or false is returned. Why is this and is it a problem that I should be aware of and I should fox?
I am using web services to get the parameter from SOAP client successfully. I want to pass this parameters in url through html form so that i can connect to my system with this parameters. I have 2 functions. Function login() is to set the parameters for the connection from SOAP client and function getVehicle() to get this parameters. In getVehicle() i want to send the parameters user, hash password, dealer_number, corporate_group_id to client.php from url. And this parameters i want to send from form action without submit button.
index.php
function login()
{
$wsdl = 'http://www.schwackenet.de/awonline/de/service2/SNWebService.php?wsdl';
$options = array('trace' => true);
$params = array(
'user' => utf8_encode('deshmukh'),
'password' => utf8_encode('deshmukh'),
'corporate_group_id' => '101',
'dealer_number' => 'INT31303',
'dms_id' => 'A13T2D19',
'dms_image_url' => '',
'dms_keepalive_url' => '',
'dms_followup_url' => ''
);
$client = new SoapClient($wsdl, $options);
$result = $client->Login($params);
return $return;
}
if($parameter['aktion'] == 'getVehicle')
{
//var_dump(Login());
$vehicle=login();
$user_login=$vehicle['user'];
$password=$vehicle['password'];
$dealer_no=$vehicle['dealer_number'];
$group_id=$vehicle['corporate_group_id'];
//form action here
}
You can have the data transferred to your client.php as a GET request using the built-in php function file_get_contents() like this:
if ($parameter['aktion'] == 'getVehicle')
{
$vehicle=login();
$user_login=$vehicle['user'];
$password=$vehicle['password'];
$dealer_no=$vehicle['dealer_number'];
$group_id=$vehicle['corporate_group_id'];
// send the data to your system
$system_url = 'http://yoursite.com/path/to/client.php';
header("Location: $system_url?user=$user_login&password=$password&dealer_number=$dealer_no&corporate_group_id=$group_id");
exit();
}
If you want, you can have client.php reurn a "success" or "error" output and you'll have it on the $response variable and you can log it or do something else with it.
In your login() you are returning $return, that is wrong. You need to return $result, which is holding the result from curl request.
function login()
{
$wsdl = 'http://www.schwackenet.de/awonline/de/service2/SNWebService.php?wsdl';
$options = array('trace' => true);
$params = array(
'user' => utf8_encode('deshmukh'),
'password' => utf8_encode('deshmukh'),
'corporate_group_id' => '101',
'dealer_number' => 'INT31303',
'dms_id' => 'A13T2D19',
'dms_image_url' => '',
'dms_keepalive_url' => '',
'dms_followup_url' => ''
);
$client = new SoapClient($wsdl, $options);
$result = $client->Login($params);
return $result;
}
if($parameter['aktion'] == 'getVehicle')
{
$vehicle=login();
var_dump($vehicle);
}
I am making a start on SOAP but can't get past the first hurdle of authenticating myself...
Here is my code...
$login = array(
'loginWebRequest' => array(
'Username' => 'myuser',
'Password' => 'mypass'
)
);
$url = 'https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl';
$client = new SoapClient($url);
$result = $client->Login('Login',$login);
print_r($result);
I hope someone can see a mistake I have obviously made!
print_r($client->__getFunctions());
tells me this...
Array
(
[0] => LoginResponse Login(Login $parameters)
[1] => LogoutResponse Logout(Logout $parameters)
)
Thanks in advance
Paul
Try this:
$options = array(
"trace" => 1,
"exception" => 1
);
$login = array(
'loginWebRequest' => array(
'Username' => 'myuser',
'Password' => 'mypass'
)
);
$url = 'https://qa-api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl';
$client = new SoapClient($url,$options);
$result = $client->call('Login',$login);
echo "<pre>";
print_r($client->__getLastRequest());
echo "<hr />";
print_r($result);
I recomend the use of soapui before any code, is importante to test de wsdl functions and permissions. In SOAPUI you can do a call for login function and it is more fast and easy to check for example login and password information.