passing parameters in url through form action in php functions - php

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);
}

Related

HTTP Guzzle not returning all data

I have created a function that contacts a remote API using Guzzle but I cannot get it to return all of the data available.
I call the function here:
$arr = array(
'skip' => 0,
'take' => 1000,
);
$sims = api_request('sims', $arr);
And here is the function, where I have tried the following in my $response variable
json_decode($x->getBody(), true)
json_decode($x->getBody()->getContents(), true)
But neither has shown any more records. It returns 10 records, and I know there are over 51 available that it should be returning.
use GuzzleHttp\Client;
function api_request($url, $vars = array(), $type = 'GET') {
$username = '***';
$password = '***';
//use GuzzleHttp\Client;
$client = new Client([
'auth' => [$username, $password],
]);
$auth_header = 'Basic '.$username.':'.$password;
$headers = ['Authorization' => $auth_header, 'Content-Type' => 'application/json'];
$json_data = json_encode($vars);
$end_point = 'https://simportal-api.azurewebsites.net/api/v1/';
try {
$x = $client->request($type, $end_point.$url, ['headers' => $headers, 'body' => $json_data]);
$response = array(
'success' => true,
'response' => // SEE ABOVE //
);
} catch (GuzzleHttp\Exception\ClientException $e) {
$response = array(
'success' => false,
'errors' => json_decode($e->getResponse()->getBody(true)),
);
}
return $response;
}
By reading the documentation on https://simportal-api.azurewebsites.net/Help/Api/GET-api-v1-sims_search_skip_take I assume that the server is not accepting your parameters in the body of that GET request and assuming the default of 10, as it is normal in many applications, get requests tend to only use query string parameters.
In that function I'd try to change it in order to send a body in case of a POST/PUT/PATCH request, and a "query" without json_encode in case of a GET/DELETE request. Example from guzzle documentation:
$client->request('GET', 'http://httpbin.org', [
'query' => ['foo' => 'bar']
]);
Source: https://docs.guzzlephp.org/en/stable/quickstart.html#query-string-parameters

Typo 3: Create user on FE login

The situation:
I build an authentication service that uses Basic Authentication to check if the user exists on an external database and fetches some data. The users in question only exist on the external database.
The problem:
Typo3 needs to have an user entry in the fe_user table to login the user.
So whenever this entry does not exist, the user cannot login.
What I want to do:
Create the user in the authentication service to avoid using a sql dump from the external database and ensure that synchronisation is possible.
The relevant code:
public function authUser(array $user) {
$a_user = $this->login['uname'];
$a_pwd = $this->login['uident_text'];
$url = 'https://soliday.fluchtpunkt.at/api/queryMediaItems';
$data = json_decode('{"language":"de-at"}');
$basicAuth = base64_encode("$a_user:$a_pwd");
// use key 'http' even if you send the request to https://...
$options = array (
'http' => array (
'header' => array(
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Basic {$basicAuth}"
),
'method' => 'POST',
'content' => '{"language":"de-at"}'
)
);
$context = stream_context_create ( $options );
$result = file_get_contents ($url, false, $context);
$response = gzdecode($result);
$checkUser = $this->fetchUserRecord ( $this->login ['uname'] );
if (!is_array($checkUser)&& $result!== FALSE) {
$this->createUser();
}
// failure
if ($result === FALSE) {
return static::STATUS_AUTHENTICATION_FAILURE_BREAK;
}
$this->processData($response);
// success
return static::STATUS_AUTHENTICATION_SUCCESS_BREAK;
}
public function createUser() {
$username = $this->login ['uname'];
$password = $this->login ['uident_text'];
$record = $GLOBALS ['TYPO3_DB']->exec_SELECTgetSingleRow ( '*', 'fe_users', "username = '" . $username . "' AND disable = 0 AND deleted = 0" );
if (! $record) {
// user has no DB record (yet), create one using defaults registered in extension config
// password is not important, username is set to the user's input
$record = array (
'username' => $username,
'password' => $password,
'name' => '',
'email' => '',
'disable' => '0',
'deleted' => '0',
'pid' => $this->config ['storagePid'],
'usergroup' => $this->config ['addUsersToGroups'],
'tstamp' => time ()
);
if (t3lib_extMgm::isLoaded ( 'extbase' )) {
$record ['tx_extbase_type'] = $this->config ['recordType'];
}
$GLOBALS ['TYPO3_DB']->exec_INSERTquery ( 'fe_users', $record );
$uid = $GLOBALS ['TYPO3_DB']->sql_insert_id ();
$record = $GLOBALS ['TYPO3_DB']->exec_SELECTgetSingleRow ( '*', 'fe_users', 'uid = ' . intval ( $uid ) );
}
$_SESSION [$this->sessionKey] ['user'] ['fe'] = $record;
}
the ext_localconf.php file:
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
$_EXTKEY,
'auth' /* sv type */,
'AuthService' /* sv key */,
array(
'title' => 'GET Authentication service',
'description' => 'Authenticates users with GET request.',
'subtype' => 'getUserFE, authUserFE',
'available' => true,
'priority' => 90,
'quality' => 90,
'os' => '',
'exec' => '',
'className' => Plaspack\professionalZoneLogin\Service\AuthService::class,
)
);
You should extend AuthenticationService with your own code, way of doing that is described here https://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Xclasses/Index.html
Not sure if it's related, but t3lib_extMgm should be \TYPO3\CMS\Core\Utility\ExtensionManagementUtility unless you're using TYPO3 6.
You can also see if you get any SQL errors by calling $GLOBALS['TYPO3_DB']->sql_error().

POST request in PHP is returning PHP code when file extension is used

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?

error in calling soap function in php

how can i get soap data in php from this site
http://www2.rlcarriers.com/freight/shipping-resources/rate-quote-instructions
they have "GetRateQuote(string APIKey, RequestObjects.RateQuoteRequest request)"
this function how can i call this from php soap
$client = new SoapClient('http://api.rlcarriers.com/1.0.1/RateQuoteService.asmx?WSDL');
//print_r($client);
//$result = $client->GetRateQuote('xxxxxxxxxxxxxxxxxxxxxx.......',);
print_r($result);
?>
what should i have to pass in second parameter
Try the following:
$client = new SoapClient("http://api.rlcarriers.com/1.0.1/ShipmentTracingService.asmx?WSDL", array("trace" => 1));
$request = array(
"APIKey" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"request" => array(
"TraceNumbers" => array(
0 => "xxxxxxxxx"
),
"TraceType" => "PRO",
"FormatResults" => "true",
"IncludeBlind" => "true",
"OutputFormat" => "Standard"
)
);
try {
$response = $client->TraceShipment($request);
print_r($response);
}
catch (SoapFault $exception) {
print_r($exception);
}

Session not brougt at codeigniter curl request

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);

Categories