I am trying to write an SSO plugin for my WordPress multisite and MemberSuite. I'm in the beginning steps, just trying to have the user sign in and get the MemberSuite sign-in token.
Here's the code I have so far:
define("MS_API_URL", "http://rest.membersuite.com/swagger/platform/v2/");
define("TENANT_ID", "00000");
define("USER_POOL", "placeholder");
define("CLIENT_ID", "placeholder");
function send_request() {
$username = $_POST[portalusername];
$password = $_POST[portalpassword];
return ms_sign_in($username, $password, USER_POOL, CLIENT_ID);
}
function ms_sign_in($un, $pw, $up, $cid) {
$url = MS_API_URL . 'storeJWTTokenForUser/' . TENANT_ID;
$data = array(
'username' => $un,
'password' => $pw,
'userPool' => $up,
'clientID' => $cid
);
$arguments = array(
'method' => 'POST',
'headers' => array(
'Content-Type' => 'application/json',
'Accept' => 'application/json'
),
'body' => json_encode($data)
);
echo "before post";
$response = wp_remote_post($url, $arguments);
echo "after post";
if ( is_wp_error( $response ) ) {
$error_message = $response->get_error_message();
echo "Something went wrong: $error_message";
}
echo $response;
echo $response['body'];
return $response['body'];
}
?>
<html>
<body>
<p>body 1</p>
<?php echo send_request();?>
<p>body 2</p>
</body>
</html>
My form calls the send_request() function. As far as I can tell, I've implemented everything the way the MemberSuite documentation indicates it should be implemented. I've included all the necessary values for verification.
However, it appears execution just stops when I reach the line that says $response = wp_remote_post($url, $arguments);. The output displays:
body 1
before post
but nothing else. I'd like to know why this happening, if there is any way to fix it, and/or if there is a different way I should go about making the POST request.
Related
I am trying to Ping a URL with name, email, and list variable in the URL. Exp:
https://myurl.com/?name=Example-Name&email=example#email.com&list=123456789hak.
So I am using $_GET to grab the variables from the URL, and want to then insert into a database using a POST array.
The code seems to grab the variables correctly, but the array fails inserting. Can anybody see where I am going wrong?
Language is PHP. This is supposed to insert contacts into Sendy via their API.
Here is the code:
<?php
//-------------------------- You need to set these --------------------------//
$your_installation_url = 'https://myURL.com'; //Your Sendy installation (without the trailing slash)
$api_key = 'API CODE FOR THE DATABASE IS HERE'; //Can be retrieved from your Sendy's main settings
$success_url = 'http://google.com'; //URL user will be redirected to if successfully subscribed
$fail_url = 'http://yahoo.com'; //URL user will be redirected to if subscribing fails
//---------------------------------------------------------------------------//
//POST variables
$name = $_GET['name'];
$email = $_GET['email'];
$list = $_GET['list'];
$boolean = 'true';
//Check fields
if($name=='' || $email=='')
{
echo 'Please fill in all fields.';
exit;
}
//Subscribe
$postdata = http_build_query(
array(
'name' => $name,
'email' => $email,
'list' => $list,
'api_key' => $api_key,
'boolean' => 'true'
)
);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
$result = file_get_contents($your_installation_url.'/subscribe', false, $context);
//check result and redirect
if($result)
header("Location: $success_url");
else
header("Location: $fail_url");
?>
Thanks!
Again I came up with new google captcha question.
I have a view file with the following code :
<p>
<div class="g-recaptcha" data-sitekey="MY_SITE_KEY"></div>
</p>
Above code obviously under form element.
And after that,
In my controller, I am writing this as follows,
if ($this->form_validation->run() == TRUE) {
$recaptchaResponse = trim($this->input->post('g-recaptcha-response'));
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => 'MY_SECRET_KEY',
'response' => $recaptchaResponse
);
$options = array(
'http' => array (
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);
#echo "<pre>"; print_r($captcha_success);die;
if ($captcha_success->success==false) {
echo "<p>You are a bot! Go away!</p>";
} else if ($captcha_success->success==true) {
echo "<p>You are not not a bot!</p>";
}
die;
}
But still it is not working form me.
Actually, I have registered my localhost url with Google account and I have different secret key and site key for the local and for the live one. But when I tried to use captcha, both live and local gives me same json output as the following one.
{
"success": false,
"error-codes": [
"missing-input-response"
]
}
Please suggest, how to overcome with this.
Thank You.
You are probably getting the error message, missing-input-response, because you are not passing the parameter "response" correctly.
Can you update your question with your code you are using for the call to the captcha API?
I am working on this legacy system that needs to maintain its SOAP service, and I am currently trying to integrate it with codeigniter, keeps giving me an error XML error parsing SOAP payload on line 70: Reserved XML Name. I have tried the trim solution that someone mention and that did not work. It does not give me this error with normal arrays. Only multidimensional arrays. Any advice would be appreviated
<?php
class Employee_Trainings_Soap extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->library("Soap_lib");
$this->nusoap_server = new soap_server();
}
public function employee_detail() {
$namespace = 'http://localhost/employee_trainings_soap/employee_detail?wsdl';
$this->nusoap_server->debug_flag = true;
$this->nusoap_server->configureWSDL('EmployeeTrainings', $namespace);
$this->nusoap_server->wsdl->schemaTargetNamespace = $namespace;
$this->nusoap_server->wsdl->addComplexType('response', 'complexType', 'struct', 'all', '', array(
"validOPIN" => array(
"name" => "valid_OPIN",
"type" => "xsd:string"
),
"message" => array(
"name" => "message",
"type" => "xsd:string"
)
));
$this->nusoap_server->wsdl->addComplexType('responses', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
array(
"ref" => "SOAP-ENC:arrayType",
"wsdl:arrayType" => "tns:response[]"
)),
"tns:response"
);
$this->nusoap_server->register('getEmployeeTrainings', array("id" => "xsd:string"), array('test'=>'tns:responses'),
$namespace, $namespace."#getEmployeeTrainings", "rpc", "encoded",
'Use this service to list notaries connected to the signed-in title company.'
);
function getEmployeeTrainings($id) {
$data = array();
$data[] = array('valid_OPIN'=>'test','message'=>'test2');
$data[] = array('valid_OPIN'=>'test','message'=>'test2');
//$data = array('valid_OPIN'=>'test','message'=>'test2');
return array('test'=>$data);
}
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$this->nusoap_server->service($POST_DATA);
}
function live_client_test() {
$this->soapclient = new nusoap_client('http://localhost/employee_trainings_soap/employee_detail');
$err = $this->soapclient->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $this->soapclient->call('getEmployeeTrainings', array('id' => 'test'));
if ($this->soapclient->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
$err = $this->soapclient->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
}
}
So I have found the issue, this may not be the only solution, it is the solution that we found that worked for us. We had to take the SOAP Service out of Code Igniter for it to work. The moment that we took the service outside of Code Igniter, it worked. This may be a bug with code igniter or it could have been with the way we were using it, but as a quick solution it worked. Additionally, we also found it worked better on a Linux dev box compared to an XAMPP dev box. I hope this helps anyone else that might have the same issue.
I am trying to implement a web service using PHP. I am following xml-rpc protocol.
I am trying to call a function through index file and display records from the database but when i try to call the function in file server2 nothing is printed on the screen just a blank white screen is showed up here is my code so far.
Kindly help me out with this I have spent hours searching about this but cannot find any help
server2.php
<?php
$request_xml = file_get_contents("php://input");
function say_hello($method_name, $args) {
$dbLink = mysqli_connect('localhost','root','saad','enstructo');
if (!$dbLink) {
echo "ERROR";
}
$query = "SELECT * FROM Admin";
if ($result = mysqli_query($dbLink,$query)) {
while($getquery = mysql_fetch_array($result)){
$returnquery[] =array($result['username'],$result['email']) ;
}
}
return $returnquery;
}
$xmlrpc_server = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server, "say_hello", "say_hello");
header('Content-Type: text/xml');
print xmlrpc_server_call_method($xmlrpc_server, $request_xml, array());
?>
index.php
<?php
$request = xmlrpc_encode_request("say_hello", array('10'));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\n",
'content' => $request
)));
$server = 'http://localhost/rpc/basic/server2.php';
$file = file_get_contents($server, false, $context);
$response = xmlrpc_decode($file);
echo $response;
?>
I am trying to make a POST request using cURL in PHP. I have the code to make the POST request (from index.php) and I believe it is correct.
The next part is the API layer (api.php) which needs to extract the data from the POST request and this is where I am having issues. In the code, I am trying to read the value of the parameter q that I have passed using index.php.
Here's the code for both the files.
index.php
<?php
$handle = curl_init();
curl_setopt_array(
$handle,
array(
CURLOPT_URL => 'http://localhost:8888/restAPI/api.php',
'q' => 'getCompanyId',
'post_fields' => 'q=getCompanyId',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array(
'q' => 'getCompanyId'
),
CURLOPT_RETURNTRANSFER => true
)
);
$response = curl_exec($handle);
curl_close($handle);
?>
api.php
<?php
require_once("Rest.inc.php");
class API extends REST {
public function processApi() {
$func = $_REQUEST['q'];
if((int)method_exists($this,$func) > 0){
$this->$func();
}
else{
$this->response('',404);
// If the method not exist with in this class, response would be "Page not found".
}
}
public function getCompanyId(){
$dbhost = 'localhost:8888';
$conn = mysql_connect($dbhost, 'root', 'root');
if (! $conn) {
die('Could not connect - ' . mysql_error());
}
$sql = 'SELECT companyId FROM Companies';
mysql_select_db('IRSocialBackend');
$executeSql = mysql_query($sql);
while($data = mysql_fetch_array($executeSql)){
echo $data['companyId'];
}
}
}
//echo "here";
$api = new API;
$api -> processApi();
?>
Just a side note: your API is not RESTFUL. REST is not a matter of "making HTTP requests". Read up on it!
First mistake:
array(
CURLOPT_URL => 'http://localhost:8888/restAPI/api.php',
'q' => 'getCompanyId',
'post_fields' => 'q=getCompanyId',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array(
'q' => 'getCompanyId'
),
CURLOPT_RETURNTRANSFER => true
)
Random "q" and "post_fields" is definitely not how you add fields to curlopt.
In api.php, you assign the following:
$dbhost = 'localhost:8888';
$conn = mysql_connect($dbhost, 'root', 'root');
I thought localhost:8888 was your webserver? localhost:3306 would be your MySQL server if it is on a default port.
The rest is hard to debug without knowing your table/DB structure.