Fatal error: Uncaught Error: Call to undefined function app_create() - php

I am trying to use serverPilot API from my website. I have created simple functions like below for sample usage but its giving me error like below
Fatal error: Uncaught Error: Call to undefined function app_create()
I am new in PHP and don't know proper method to declare and use functions. Let me know what I am missing in this? My full PHP code is like below
<?php
if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['createApp'])){
$name = "sampleName";
$name = "hello";
$runtime ="php5.5";
$password = "Test#123";
$domains = array("www.example.com","example2.com");
app_create( $name, $sysuserid, $runtime, $domains = array());
}
else if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['createDb'])){
$id = 1;
$name = "hello";
$username ="testuser";
$password = "Test#123";
database_create( $id, $name, $username, $password );
}
else if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['createUser'])){
$id = 1;
$name = "hello";
$password = "Test#123";
sysuser_create( $id, $name, $password = NULL )();
}
class ServerPilot {
// variables
public $apiID = "";
public $apiKey = "";
public $decode;
// constants
const SP_API_ENDPOINT = 'https://api.serverpilot.io/v1/';
const SP_USERAGENT = 'ServerPilot-PHP/1.0';
const SP_HTTP_METHOD_POST = 'post';
const SP_HTTP_METHOD_GET = 'get';
const SP_HTTP_METHOD_DELETE = 'delete';
// error constants
const SP_MISSING_CONFIG = 'Missing config data';
const SP_MISSING_API = 'You must provide API credentials';
const SP_CURL_ERROR = 'Curl error code returned ';
public function __construct( $config = array() ) {
if( empty($config) ) throw new Exception(ServerPilot::SP_MISSING_CONFIG);
if( !isset($config['id']) || !isset($config['key']) ) throw new Exception(ServerPilot::SP_MISSING_API);
$this->apiID = $config['id'];
$this->apiKey = $config['key'];
$this->decode = ( isset($config['decode']) ) ? $config['decode'] : true;
}
public function sysuser_create( $id, $name, $password = NULL ) {
$params = array(
'serverid' => $id,
'name' => $name);
if( $password )
$params['password'] = $password;
return $this->_send_request( 'sysusers', $params, ServerPilot::SP_HTTP_METHOD_POST );
}
public function app_create( $name, $sysuserid, $runtime, $domains = array() ) {
$params = array(
'name' => $name,
'sysuserid' => $sysuserid,
'runtime' => $runtime);
if( $domains )
$params['domains'] = $domains;
return $this->_send_request( 'apps', $params, ServerPilot::SP_HTTP_METHOD_POST );
}
public function database_create( $id, $name, $username, $password ) {
$user = new stdClass();
$user->name = $username;
$user->password = $password;
$params = array(
'appid' => $id,
'name' => $name,
'user' => $user);
return $this->_send_request( 'dbs', $params, ServerPilot::SP_HTTP_METHOD_POST );
}
private function _send_request( $url_segs, $params = array(), $http_method = 'get' )
{
// Initialize and configure the request
$req = curl_init( ServerPilot::SP_API_ENDPOINT.$url_segs );
curl_setopt( $req, CURLOPT_USERAGENT, ServerPilot::SP_USERAGENT );
curl_setopt( $req, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
curl_setopt( $req, CURLOPT_USERPWD, $this->apiID.':'.$this->apiKey );
curl_setopt( $req, CURLOPT_RETURNTRANSFER, TRUE );
// Are we using POST or DELETE? Adjust the request accordingly
if( $http_method == ServerPilot::SP_HTTP_METHOD_POST ) {
curl_setopt( $req, CURLOPT_HTTPHEADER, array('Content-Type: application/json') );
curl_setopt( $req, CURLOPT_POST, TRUE );
curl_setopt( $req, CURLOPT_POSTFIELDS, json_encode($params) );
}
if( $http_method == ServerPilot::SP_HTTP_METHOD_DELETE ) {
curl_setopt( $req, CURLOPT_CUSTOMREQUEST, "DELETE" );
}
// Get the response, clean the request and return the data
$response = curl_exec( $req );
$http_status = curl_getinfo( $req, CURLINFO_HTTP_CODE );
curl_close( $req );
// Everything when fine
if( $http_status == 200 )
{
// Decode JSON by default
if( $this->decode )
return json_decode( $response );
else
return $response;
}
// Some error occurred
$data = json_decode( $response );
// The error was provided by serverpilot
if( property_exists( $data, 'error' ) && property_exists( $data->error, 'message' ) )
throw new ServerPilotException($data->error->message, $http_status);
// No error as provided, pick a default
switch( $http_status )
{
case 400:
throw new ServerPilotException('We couldn\'t understand your request. Typically missing a parameter or header.', $http_status);
break;
case 401:
throw new ServerPilotException('Either no authentication credentials were provided or they are invalid.', $http_status);
break;
case 402:
throw new ServerPilotException('Method is restricted to users on the Coach or Business plan.', $http_status);
break;
case 403:
throw new ServerPilotException('Forbidden.', $http_status);
break;
case 404:
throw new ServerPilotException('You requested a resource that does not exist.', $http_status);
break;
case 409:
throw new ServerPilotException('Typically when trying creating a resource that already exists.', $http_status);
break;
case 500:
throw new ServerPilotException('Something unexpected happened on ServerPilot\'s end.', $http_status);
break;
default:
throw new ServerPilotException('Unknown error.', $http_status);
break;
}
}
}
?>
<html>
<body>
<form action="server.php" method="post">
<input type="submit" name="createApp" value="Create APP" />
</form>
</br>
<form action="server.php" method="post">
<input type="submit" name="createDb" value="Create DB" />
</form>
</br>
<form action="server.php" method="post">
<input type="submit" name="createUser" value="Create USER" />
</form>
</body>
</html>
Its giving error in all three functions same. Letme know if someone can help me for come out from this issue, I am trying from last two hours and its not working.
Thanks

You can not access class function directly like this.You need to create class object first and then call the function with object variable.
It's better to save class code in a separate file and include it in the above give file at the top to avoid errors.
E.g:
// $config as array, You need it to set in construct method.check construct method.
$config = [
"id" => ENTER_ID,
"key" => ENTER_KEY,
"decode" => true, //Optional you can leave this ,default is true anyway.
];
$ServerPilot_Obj = New ServerPilot($config);
$ServerPilot_Obj->app_create( $name, $sysuserid, $runtime, $domains = array());

Related

How can I get user profile on battle.net oauth

I'm tring to login with Blizzard ID in my site.
I think my code is work. User profile request failed.
I don't understand Blizzard's user profile Data structure.
Can you help me to get user's Id, Email and Battle Tag?
Here's my code
<?php
class Hybrid_Providers_Kakao extends Hybrid_Provider_Model_OAuth2
{
/**
* initialization
*/
function initialize()
{
parent::initialize();
// Provider API end-points
$this->api->api_base_url = "https://kr.api.battle.net/";
$this->api->authorize_url = "https://kr.battle.net/oauth/authorize";
$this->api->token_url = "https://kr.battle.net/oauth/token";
// redirect uri mismatches when authenticating with Battle.
if (isset($this->config['redirect_uri']) && !empty($this->config['redirect_uri'])) {
$this->api->redirect_uri = $this->config['redirect_uri'];
}
}
/**
* finish login step
*/
function loginFinish()
{
$error = (array_key_exists('error', $_REQUEST)) ? $_REQUEST['error'] : "";
// check for errors
if ( $error ){
throw new Exception( "Authentication failed! {$this->providerId} returned an error: $error", 5 );
}
// try to authenicate user
$code = (array_key_exists('code', $_REQUEST)) ? $_REQUEST['code'] : "";
try{
$this->authenticate( $code );
}
catch( Exception $e ){
throw new Exception( "User profile request failed! {$this->providerId} returned an error: $e", 6 );
}
// check if authenticated
if ( ! $this->api->access_token ){
throw new Exception( "Authentication failed! {$this->providerId} returned an invalid access token.", 5 );
}
// store tokens
$this->token("access_token", $this->api->access_token);
$this->token("refresh_token", $this->api->refresh_token);
$this->token("expires_in", $this->api->access_token_expires_in);
$this->token("expires_at", $this->api->access_token_expires_at);
// set user connected locally
$this->setUserConnected();
}
/**
* load the user profile
*/
function getUserProfile()
{
$this->api->decode_json = false;
$this->api->curl_header = array( 'Authorization: Bearer ' . $this->api->access_token );
$data = $this->api->api("account/profile", "POST");
if ( ! isset( $data->id ) ) {
throw new Exception("User profile request failed! {$this->providerId} returned an invalid response.", 6);
}
# store the user profile.
$this->user->profile->identifier = # $data->id;
$this->user->profile->displayName = # $data->battletag;
return $this->user->profile;
}
private function authenticate($code)
{
$params = array(
"response_type" => $code,
"grant_type" => "authorization_code",
"client_id" => $this->api->client_id,
"redirect_uri" => $this->api->redirect_uri,
"state" => $token,
"scope" => "sc2.profile",
);
if( $this->api->client_secret && ($this->api->client_secret !== $this->api->client_id) ){
$params['client_secret'] = $this->api->client_secret;
}
$response = $this->request($this->api->token_url, $params, $this->api->curl_authenticate_method);
$response = $this->parseRequestResult($response);
if ( ! $response || ! isset($response->access_token) ) {
throw new Exception("The Authorization Service has return: " . $response->error);
}
if ( isset($response->access_token) ) $this->api->access_token = $response->access_token;
if ( isset($response->refresh_token) ) $this->api->refresh_token = $response->refresh_token;
if ( isset($response->expires_in) ) $this->api->access_token_expires_in = $response->expires_in;
// calculate when the access token expire
if ( isset($response->expires_in) ) {
$this->api->access_token_expires_at = time() + $response->expires_in;
}
return $response;
}
private function request($url, $params=false, $type="GET")
{
if(Class_exists('Hybrid_Logger')){
Hybrid_Logger::info("Enter OAuth2Client::request( $url )");
Hybrid_Logger::debug("OAuth2Client::request(). dump request params: ", serialize( $params ));
}
$this->http_info = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT , $this->api->curl_time_out);
curl_setopt($ch, CURLOPT_USERAGENT , $this->api->curl_useragent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->api->curl_connect_time_out);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->api->curl_ssl_verifypeer);
curl_setopt($ch, CURLOPT_HTTPHEADER , $this->api->curl_header);
if ( $this->api->curl_proxy ) {
curl_setopt( $ch, CURLOPT_PROXY, $this->curl_proxy);
}
if ( $type == "POST" ) {
curl_setopt($ch, CURLOPT_POST, 1);
if ($params) curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query($params) );
}
$response = curl_exec($ch);
if(Class_exists('Hybrid_Logger')){
Hybrid_Logger::debug( "OAuth2Client::request(). dump request info: ", serialize(curl_getinfo($ch)) );
Hybrid_Logger::debug( "OAuth2Client::request(). dump request result: ", serialize($response ));
}
$this->http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$this->http_info = array_merge($this->http_info, curl_getinfo($ch));
curl_close ($ch);
return $response;
}
private function parseRequestResult($result)
{
if ( json_decode($result) ) return json_decode($result);
parse_str( $result, $ouput );
$result = new StdClass();
foreach( $ouput as $k => $v )
$result->$k = $v;
return $result;
}
}
I think this code can't read user id
$this->user->profile->identifier = # $data->id;
$this->user->profile->displayName = # $data->battletag;
on this part.
It's not pure HybridAuth.

WordPress - Issues with referencing custom PHP class in functions.php

I apologize if this is really dumb/obvious but this is my first experience working with classes in WordPress.
I made a class called SharpSpringService.php inside my custom plugin sharpspring-form. I placed the class within a classes folder within that custom plugin for organization purposes.
I'm referencing the SharpSpringService class within a function in functions.php but am getting an error. When I declare a new instance of SharpSpringService and place the account ID and secret key as parameters, I get a message: "Expected SharpSpring, got string". I also see an Internal Server 500 Error in the Chrome dev consoles that seems to be a result of creating an instance of this class.
I'm not sure why the parameters are expected to be "SharpSpring" as they should be accountID and secretkey.
Here is the SharpSpringService class:
private $authError = false;
private $accountID = null;
private $secretKey = null;
/**
* SharpSpringService constructor.
* #param $accountID SharpSpring Account ID
* #param $secretKey SharpSpring Secret Key
*/
public function __construct($accountID, $secretKey)
{
$this->accountID = $accountID;
$this->secretKey = $secretKey;
}
public function hasAuthError() {
return $this->authError;
}
public function makeCall($method, $params = []) {
$requestID = session_id();
$accountID = $this->accountID;
$secretKey = $this->secretKey;
$data = array(
'method' => $method,
'params' => $params,
'id' => $requestID,
);
$queryString = http_build_query([
'accountID' => $accountID,
'secretKey' => $secretKey
]);
$url = "http://api.sharpspring.com/pubapi/v1/?$queryString";
$data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
));
$result = curl_exec($ch);
curl_close($ch);
$resultObj = json_decode($result);
if ($resultObj->error != null) {
throw new \Exception($result->error);
}
return $resultObj;
}
}
And here is the function in functions.php that is referencing the class:
function get_memberships_callback(){
$newsListID = 550280195;
$listName = "NewsList";
$contactEmail = $_POST['contactemail'];
$sharpSpringService = new SharpSpringService('[redacted]', '[redacted]'); //this is where the code chokes
$return = [];
if($contactEmail != null && $contactEmail !=""){
$lists = $sharpSpringService->makeCall('getListMemberships', [
'emailAddress' => $contactEmail,
]);
if (count($lists) > 0) {
$listArray = json_decode(json_encode($lists), true);
$inNewsList = false;
foreach($listArray as $list){
if($list = $newsListID){
//the user is subscribed to the news list
$inNewsList = true;
$converted_result = ($inNewsList) ? 'true' : 'false';
}
}
}
$return[] = array(
"status" => $converted_result,
"list" => $listName
);
return json_encode($return);
}
else{
return $return;
}
die();
}
For calling numerous files, it is sometimes convenient to define a constant:
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
include( MY_PLUGIN_PATH . 'includes/admin-page.php');
include( MY_PLUGIN_PATH . 'includes/classes.php');

wp_set_auth_cookie() not working for some users only

I have a login form and using REST api service for login to the Wordpress. I can login to the wordpress using the form. But for some users wp_set_auth_cookie() function not working and I am getting 502 bad gateway. Can any one help me for sort out this?
This is my login endpoint function
function user_authentication() {
global $wp_rest_auth_cookie;
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
throw new Exception('Request method must be POST!');
}
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
throw new Exception('Content type must be: application/json');
}
$content = trim(file_get_contents("php://input"));
$decoded = json_decode($content, true);
if(!is_array($decoded)){
throw new Exception('Received content contained invalid JSON!');
}
$user_data['user_login'] = $decoded['username'];
$user_data['user_password'] = $decoded['password'];
$user_data['remember'] = false;
$user = wp_signon( $user_data, false );
if ( !is_wp_error( $user ) ) {
wp_clear_auth_cookie();
wp_set_current_user ( $user->ID);
wp_set_auth_cookie ( $user->ID );
$wp_rest_auth_cookie = wp_create_nonce('wp-rest') ;
$token = encrypt_decrypt('encrypt',$user->ID);
$name = get_name($user->ID);
$response = array(
'status'=> 'success',
'token' => $token,
'username' => $name,
'uname' => $user->ID
);
return json_encode( $response);
}else{
$response = array(
'status' => 'fail',
'message'=> "The username and password you entered don't match."
);
return json_encode($response);
}
die();
}
Add below code into your code and check wp_set_auth_cookie working or not.
$user_data['user_login'] = $decoded['username'];
$user_data['user_password'] = $decoded['password'];
$user_data['remember'] = true;
$user = wp_signon( $user_data, false );
if ( !is_wp_error( $user ) ) {
wp_set_auth_cookie( $user->ID, true );
} else {
echo $user->get_error_message();
}
I have solved this myself. There was some undefined variable errors along with the api response. Those errors was conflicting with the wp_set_auth_cookie() function. When I fixed those errors from my code, the 502 bad gate way issue get solved.

PHP Accessing one array from class

I'm trying to access a single value of an array, I can't seem to get it right. This is the code:
$socialCounts = new socialNetworkShareCount(array(
'url' => 'http://facebook.com/',
'facebook' => true,
'buffer' => true,
'pinterest' => true,
'linkedin' => true,
'google' => true
));
print_r($socialCounts->getShareCounts());
Which Returns the following:
{"facebookshares":52132062,"facebooklikes":0,"pinterestshares":243942,"linkedinshares":4708,"googleplusones":0,"buffershares":207477,"total":52588189}
How can I access the vaule of each individual Item? For example, if I'd like to echo the facebook shares value.
And this is the full class if you need:
class socialNetworkShareCount{
public $shareUrl;
public $socialCounts = array();
public $facebookShareCount = 0;
public $facebookLikeCount = 0;
public $twitterShareCount = 0;
public $bufferShareCount = 0;
public $pinterestShareCount = 0;
public $linkedInShareCount = 0;
public $googlePlusOnesCount = 0;
public function __construct($options){
if(is_array($options)){
if(array_key_exists('url', $options) && $options['url'] != ''){
$this->shareUrl = $options['url'];
}else{
die('URL must be set in constructor parameter array!');
}
// Get Facebook Shares and Likes
if(array_key_exists('facebook', $options)){
$this->getFacebookShares();
$this->getFacebookLikes();
}
// Get Twitter Shares
if(array_key_exists('twitter', $options)){
$this->getTwitterShares();
}
// Get Twitter Shares
if(array_key_exists('pinterest', $options)){
$this->getPinterestShares();
}
// Get Twitter Shares
if(array_key_exists('linkedin', $options)){
$this->getLinkedInShares();
}
// Get Twitter Shares
if(array_key_exists('google', $options)){
$this->getGooglePlusOnes();
}
// Get Buffer Shares
if(array_key_exists('buffer', $options)){
$this->getBufferShares();
}
}elseif(is_string($options) && $options != ''){
$this->shareUrl = $options;
// Get all Social Network share counts if they are not set individually in the options
$this->getFacebookShares();
$this->getFacebookLikes();
$this->getTwitterShares();
$this->getPinterestShares();
$this->getLinkedInShares();
$this->getGooglePlusOnes();
$this->getBufferShares();
}else{
die('URL must be set in constructor parameter!');
}
}
public function getShareCounts(){
$totalShares = $this->getTotalShareCount($this->socialCounts);
$this->socialCounts['total'] = $totalShares;
return json_encode($this->socialCounts);
}
public function getTotalShareCount(array $shareCountsArray){
return array_sum($shareCountsArray);
}
public function getFacebookShares(){
$api = file_get_contents( 'http://graph.facebook.com/?id=' . $this->shareUrl );
$count = json_decode( $api );
if(isset($count->shares) && $count->shares != '0'){
$this->facebookShareCount = $count->shares;
}
$this->socialCounts['facebookshares'] = $this->facebookShareCount;
return $this->facebookShareCount;
}
public function getFacebookLikes(){
$api = file_get_contents( 'http://graph.facebook.com/?id=' . $this->shareUrl );
$count = json_decode( $api );
if(isset($count->likes) && $count->likes != '0'){
$this->facebookLikeCount = $count->likes;
}
$this->socialCounts['facebooklikes'] = $this->facebookLikeCount;
return $this->facebookLikeCount;
}
public function getTwitterShares(){
$api = file_get_contents( 'https://api.twitter.com/1.1/urls/count.json?url=' . $this->shareUrl );
$count = json_decode( $api );
if(isset($count->count) && $count->count != '0'){
$this->twitterShareCount = $count->count;
}
$this->socialCounts['twittershares'] = $this->twitterShareCount;
return $this->twitterShareCount;
}
public function getBufferShares(){
$api = file_get_contents( 'https://api.bufferapp.com/1/links/shares.json?url=' . $this->shareUrl );
$count = json_decode( $api );
if(isset($count->shares) && $count->shares != '0'){
$this->bufferShareCount = $count->shares;
}
$this->socialCounts['buffershares'] = $this->bufferShareCount;
return $this->bufferShareCount;
}
public function getPinterestShares(){
$api = file_get_contents( 'http://api.pinterest.com/v1/urls/count.json?callback%20&url=' . $this->shareUrl );
$body = preg_replace( '/^receiveCount\((.*)\)$/', '\\1', $api );
$count = json_decode( $body );
if(isset($count->count) && $count->count != '0'){
$this->pinterestShareCount = $count->count;
}
$this->socialCounts['pinterestshares'] = $this->pinterestShareCount;
return $this->pinterestShareCount;
}
public function getLinkedInShares(){
$api = file_get_contents( 'https://www.linkedin.com/countserv/count/share?url=' . $this->shareUrl . '&format=json' );
$count = json_decode( $api );
if(isset($count->count) && $count->count != '0'){
$this->linkedInShareCount = $count->count;
}
$this->socialCounts['linkedinshares'] = $this->linkedInShareCount;
return $this->linkedInShareCount;
}
public function getGooglePlusOnes(){
if(function_exists('curl_version')){
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, "https://clients6.google.com/rpc" );
curl_setopt( $curl, CURLOPT_POST, 1 );
curl_setopt( $curl, CURLOPT_POSTFIELDS, '[{"method":"pos.plusones.get","id":"p","params":{"nolog":true,"id":"' . $this->shareUrl . '","source":"widget","userId":"#viewer","groupId":"#self"},"jsonrpc":"2.0","key":"p","apiVersion":"v1"}]' );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Content-type: application/json' ) );
$curl_results = curl_exec( $curl );
curl_close( $curl );
$json = json_decode( $curl_results, true );
$this->googlePlusOnesCount = intval( $json[0]['result']['metadata']['globalCounts']['count'] );
}else{
$content = file_get_contents("https://plusone.google.com/u/0/_/+1/fastbutton?url=".urlencode($_GET['url'])."&count=true");
$doc = new DOMdocument();
libxml_use_internal_errors(true);
$doc->loadHTML($content);
$doc->saveHTML();
$num = $doc->getElementById('aggregateCount')->textContent;
if($num){
$this->googlePlusOnesCount = intval($num);
}
}
$this->socialCounts['googleplusones'] = $this->googlePlusOnesCount;
return $this->googlePlusOnesCount;
}}
According to the class definition, you don't need to invoke getShareCounts(). It looks like that method is perhaps used to provide some lower end API functionality. I don't think it's meant for your use case.
All of the below public variables are accessible and filled in once the constructor has run.
public $facebookShareCount = 0;
public $facebookLikeCount = 0;
public $twitterShareCount = 0;
public $bufferShareCount = 0;
public $pinterestShareCount = 0;
public $linkedInShareCount = 0;
public $googlePlusOnesCount = 0;
So you can access them like so:
$socialCounts = new socialNetworkShareCount(array(
'url' => 'http://facebook.com/',
'facebook' => true,
'buffer' => true,
'pinterest' => true,
'linkedin' => true,
'google' => true
));
print_r($socialCounts->facebookShareCount); // facebook shares
print_r($socialCounts->facebookLikeCount); // facebook likes
mixed json_decode ( string $json [, bool $assoc = false [, int $depth
= 512 [, int $options = 0 ]]] )
Source.
Since your json is an object, json_decode($yourparam) will return an stdClass by default, which will have public members. Since you would like to use an associated array instead, you need to call something like json_decode($yourparam, true), which will return an associated array, since the second parameter is a boolean value determined by your intention whether you want an associated array as result, default value being false.

why sometime can get error 404 not found (soapclient- response has contents of the response), how to solve

i have a NUSOAP webservice
when i run from client it visbile the error
wsdl error: Getting http://carvilshoe.cz.cc/index.wsdl.php?wsdl - HTTP ERROR: Unsupported HTTP response status 404 Not Found (soapclient->response has contents of the response)
below is my code at client
i have to client (mitra)
mitra = http://pakalolosepatu.cu.cc/
mitra1 = http://carvilshoe.cz.cc/
--
//wsdl configuration
$wsdl = mitra . 'index.wsdl.php?wsdl';
$ws_client_pakalolo = new nusoap_client ( $wsdl, true );
$wsdl = mitra1 . 'index.wsdl.php?wsdl';
$ws_client_sepatubermerek = new nusoap_client ( $wsdl, true );
//debug if needed
//$ws_client->debugLevel = 1;
//header configuration
$user = "+++";
$pass = "+++";
//encrypt header value
$user = base64_encode ( $user );
$pass = base64_encode ( $pass );
$header = '<AuthSoapHeader>
<UserName>' . $user . '</UserName>
<Password>' . $pass . '</Password>
</AuthSoapHeader>';
//set header
$ws_client_pakalolo->setHeaders ( $header );
$ws_client_sepatubermerek->setHeaders ( $header );
// Function to print Fault
function detect_fault() {
global $ws_client_pakalolo;
//detect fault and error
if ($ws_client_pakalolo->fault) {
exit ( $ws_client_pakalolo->faultstring );
} else {
$err = $ws_client_pakalolo->getError ();
if ($err) {
exit ( $err );
}
}
}
function detect_fault_mitra2() {
global $ws_client_sepatubermerek;
//detect fault and error
if ($ws_client_sepatubermerek->fault) {
exit ( $ws_client_sepatubermerek->faultstring );
} else {
$err = $ws_client_sepatubermerek->getError ();
if ($err) {
exit ( $err );
}
}
}
function call_list_barang($limit, $offset, $order_by, $where) {
global $ws_client_pakalolo,$ws_client_sepatubermerek;
//parameters configuration
$params = array ('limit' => $limit, 'offset' => $offset, 'order_by' => $order_by, 'where' => $where);
//call method service
$ws_data = $ws_client_pakalolo->call ( 'data_barang', $params);
detect_fault ();
//decode data
$ws_data = unserialize ( base64_decode ( $ws_data ) );
//call method service
$ws_data1 = $ws_client_sepatubermerek->call ( 'data_barang', $params);
detect_fault_mitra2 ();
//decode data
$ws_data1 = unserialize ( base64_decode ( $ws_data1 ) );
$data_paka = $ws_data['data'];
$data_se = $ws_data1['data'];
$data = array_merge($data_paka,$data_se);
return $data;
}
function call_list_stock($mitra,$no_barang) {
global $ws_client_sepatubermerek, $ws_client_pakalolo;
//parameters configuration
$params = array ('no_barang' => $no_barang );
if($mitra == "Pakalolo"){
//call method service
$ws_data = $ws_client_pakalolo->call ( 'list_stock', $params);
detect_fault ();
//decode data
}else{
//call method service
$ws_data = $ws_client_sepatubermerek->call ( 'list_stock', $params);
detect_fault_mitra2 ();
//decode data
}
$ws_data = unserialize ( base64_decode ( $ws_data ) );
return $ws_data;
}
?>
why can happen this error and how to solve,
can someone help??
thanks
Try to set forced endpoint
$client = new nusoap_client('http://LOCATION_TO_WSDL','wsdl');
$client -> setEndpoint('http://LOCATION_OF_ENDPOINT');
The endpoint is a connection point where HTML files or active server pages are exposed.

Categories