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!
Related
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.
I have tried creating a RESTful API service. I have generated a token by hashing a string (using a randomly generated secret key that is stored in the database) that is returned by the login script on successful login, to the client end as a part of a JSON object. The client passes the token (along with some other fields as a JSON object) as a GET/POST parameter to get access to the other API services. However, it seems that when the token string is passed around as a JSON object, the string gets altered somewhere in the middle, and dehashing it with the secret key at the verification endpoint does not yield the same string as the string that was hashed. Result is an unsuccessful attempt at getting the data secured by the token.
I am adding parts of the code that are relevant:
Login Script
$secret = newsecret($rand);
$token = newtoken($secret, $str);
$qry1 = "UPDATE user_master set user_secret='".$secret."' where user_code='".$uid."'";
$res1 = mysqli_query($conn, $qry1);
$outdata = array("status" => "success", "username" => $un, "uid" => $uid, "token" => $token);
header('Content-type: application/json');
echo json_encode($outdata);
Client JS
$.post("http://www.ckoysolutions.com/apis/login.php", inputs).done(function(data){
if(data.status=="success") {
var inputs = '{ '
+'"uid" : "'+data.uid+'" , '
+'"token" : "'+data.token+'"'
+' }';
window.location='http://hasconpanel.ckoysolutions.com/hasconpanel.php?inputs='+inputs;
}
else {
alert(data.message);
}
});
Redirected page (http://hasconpanel.ckoysolutions.com/hasconpanel.php) sending token as json as a curl postfield for verification
if(isset($inputs->uid) && isset($inputs->token)) {
$token = $inputs->token;
$uid = $inputs->uid;
$auth_data = array("uid" => $uid, "token" => $token);
$auth_json = json_encode($auth_data);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $auth_json,
CURLOPT_URL => "http://www.ckoysolutions.com/apis/authuser.php",
CURLOPT_HTTPHEADER => [
'Content-Type: application/json'
]
]);
$result = curl_exec($curl);
curl_close($curl);
echo $result;
}
Function used in http://www.ckoysolutions.com/apis/authuser.php to authenticate
$row = mysqli_fetch_array($res);
$secret = $row['user_secret'];
$token = $token;
$un = $row['user_name'];
$words = explode(" ",$un);
$fn = $words[0];
$udetails = $row['user_log'];
$udetails = json_decode($udetails);
$uip = $udetails->ip;
$date_time = $udetails->time;
$str = $date_time.$fn.$uip;
$chkstr = decrypt($secret, $token);
if($str == $chkstr) {
$outdata = array("status" => "success");
mysqli_close($conn);
}
else {
$outdata = array("status" => "failure");
mysqli_close($conn);
}
header('Content-type: application/json');
echo json_encode($outdata);
Please do suggest what might be going wrong here.
I had a similar issue to this and found that if the token is passed as a query string parameter and contains the + character it will get removed. I discovered the issue because the call wasn't always breaking. The easiest solution for me was to replace "+" with "P".
AJAX POST and Plus Sign ( + ) — How to Encode?
I'm trying to create a Telegram API bot for clients registration , so I chose the ' setWebHook ' method and wrote some codes :
<?php
include("config.php");
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$user_id = $update["message"]["chat"]["id"];
if( $update["message"]["text"] == "/start" OR $update["message"]["text"] == "/menu" ){
$keyboard = array(
'keyboard' => array(
array("📝 Register","🔑 Login")
),'one_time_keyboard'=>true,'resize_keyboard'=>true);
$replyKeyboard = json_encode($keyboard);
$replyMessage = "Hello 😊
Welcome to our bot ✋🏼
What do you want to do ?
.
";
}
if( $update["message"]["text"] == "📝 Register"){
$replyMessage = "Please enter username :";
}
$url = $bot_url.'sendMessage';
$data = array('chat_id' => $user_id,'text' => $replyMessage,'parse_mode' => 'Markdown','reply_markup' => $replyKeyboard );
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
$update = #file_get_contents($url, false, $context);
?>
Ok so the robot shows the options for register or login , and when you choose register , it asks you username. It's ok up to here but ,
what I have to do for the rest of the registration process ??
How should I grab username and store it in database and after that grab password and store it and for other informations ?
I appreciate any logical ways for registering by telegram bots.
I wish I could completely describe my problem , I need your help my friends.
Thank you
( config.php includes database and bot token information )
As I understand from your question these are some tips maybe helpful for you:
Each message that delivers from telegram (users) have an id that tell which user sends the message(==chat_id a unique number).
Your bot should log messages and save the important parts of messages in a db. In this manner you have a track of user's conversation with your bot and you can recognize that for which question of your bot ,user answers. If you look for each Json object delivers from telegram you can see which data telegram reveals from user.
i am able to send sms via php but in that i have to mention mobile number everytime i want that with the same script i can send sms to the entries stored in my database .
here is my code:
<?php
//Your authentication key`enter code here`
$authKey = "API key";
//Multiple mobiles numbers separated by comma
$mobileNumber = "+919425386214";
//Sender ID,While using route4 sender id should be 6 characters long.
$senderId = "Social";
//Your message to send, Add URL encoding here.
$message = urlencode("Test message");
//Define route
$route = "04";
//Prepare you post parameters
$postData = array(
'authkey' => $authKey,
'mobiles' => $mobileNumber,
'message' => $message,
'sender' => $senderId,
'route' => $route
);
if (isset($_POST['submit']))
{
//API URL
$url="https://control.msg91.com/api/sendhttp.php";
// init the resource
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData
//,CURLOPT_FOLLOWLOCATION => true
));
//Ignore SSL certificate verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
//get response
$output = curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{
echo 'error:' . curl_error($ch);
}
curl_close($ch);
echo $output;
}
?>
please help so that i can send sms to my clients whom contact no. are stored in my database
You need to do some query code to do it , for your help a sample code:-
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
$mobileNumber = '';
$conn = mysqli_connect('localhost','root','','database name') or die (mysqli_error()); // give connection credentials here
if($conn){
$query = "Select mobile_number From User"; // change table name and column name accordingly.
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
$mobileNumber .= $row['mobile_number'].',';
}
}
}
$mobileNumber = substr($mobileNumber,0,strlen($mobileNumber)-1); // now you have all mobile numbers in , seperated form in this variable
Note:- You can add this code in your current php code and do changes accordingly and you will get the output what you want.
I want to post on group wall. I have permission of "user_groups" and "publish_stream". and also access_token.
and here is my code:
try{
$statusUpdate = $this->facebook->api('/'.$group_id.'/feed', 'post',
array(
'name' => stripslashes($productname),
//'caption'=>$caption,
'message' => $message,
'description' => $description,
'picture' => $picture,
'link'=>$link));
$postid = $statusUpdate['id']; // return id
} catch (Exception $e){
$postid = 0;
}
return $postid; // return id
}
When I run this code I get a return id which was the page id. but nothing post on my group wall. how to solve this?
This code works for me to post to a facebook page.
Get FB page access token ($value['access_token']) and its page id ($value['id'])
Populate the $params array
use the FB API to post your message 3.
This is a snippet
foreach ($pages as $key => $value) {
$params = array(
'access_token' => $value['access_token'],
'message' => $message
);
// ask facebook api to post the message to the selected page
$facebook->api()->api( "/" . $value['id'] . "/feed", 'POST', $params );
}