I am trying to make a custom User creation with ZenDesk(CRM) - php

This site helped me out a lot last time I had an issue. I was wondering why this php code was not working. Any help would be appreciated. I am trying to make a custom user creation request with ZenDesk.
I got the request to work, but when I edited the code to fit it into the actual Instance of my CRM it does not even try to make a PHP request. I verified this should be possible if the code is correct. I Just can not figure out why it is not correct.
<?php
include("config.php");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://url/api/v2/users.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"user\": {\"name\": \"$name\",
\"email\": \"$email\", \"phone\": \"$phone"}}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "email" . ":" . "password");
$phone = phone;
$email = email;
$name = name;
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
if ( !isset ($_POST['Name']) ||
!isset ($_POST['Name'] ||
!isset ($_POST['phone']
)
{
}
curl_close ($ch);
?>
<!DOCTYPE html>
<html>
<body>
<form
action="://url/agent/users/{{user.id}}/requested_tickets">
First name:<br>
<input type="text" name="name" value="name">
<br>
Last name:<br>
<input type="text" name="email" value="email">
<br><br>
<input type="text" name="phone" value="+15555555555">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a
page
called "/action_page.php".</p>
</body>
</html>

Related

PHP Curl Does Not Show Response

I have added this basic login page to server for testing curl form submitting:
<?php
if(isset($_POST['submit'])){
$email = $_POST['email'];
$password = $_POST['password'];
if($email == "email#gmail.com"){
if($password == "123456"){
echo "Correctamundo!";
}else{
echo "Wrong pass";
}
}else{
echo "Wrong Email";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<form method="POST" action="">
<input type="email" name="email" value="">
<input type="password" name="password" value="">
<input type="submit" value="Submit" name="submit">
</form>
</body>
</html>
So if the email equals to email#gmail.com && the password was 123456, the Correctamundo message appears on the page.
Now with curl at another file I've added this:
<?php
$data = array(
"email" => "email#gmail.com",
"password" => "123456",
"form" => "submit"
);
$ch = curl_init("http://sitename.com/login.php");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Allow Redirections
curl_setopt($ch, CURLOPT_POST, true); // Making a POST request
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // COOKIE-jar: To save data for cookie created for login process
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // TRUE means Don't just echo output the data instead we can store the Request response in some variable
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
Now as you can see I have passed the correct credentials as $data array. But when I load the page, I don't get the Correctamundo message as success message.
So why is that? What am I doing wrong here?

How to pass a variable from an html form to a php script?

I have watched some tutorials on how to pass a variable from a form to a php file, and cannot get anything to happen when I click the submit button. I am making a page that searches the Clash of Clans API to display the clan searched.
I just need to have the form submit the clan tag to the php script.
Here is my code. The file is a php file and the form action is blank because the php is in the file.
<?php
header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['submit'])) {
$clantag = $_POST['var'];
}
$token = Token Goes Here;
$url = "https://api.clashofclans.com/v1/clans/" . urlencode($clantag);
$ch = curl_init($url);
$headr = array();
$headr[] = "Accept: application/json";
$headr[] = "Authorization: Bearer ".$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($ch);
$data = json_decode($res, true);
curl_close($ch);
echo "<pre>";
var_dump($data);
echo "</pre>";
?>
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="button" name="submit" value="Submit">
</form>
You should replace the type of the button from "button" to "submit"
<form action="" method="post">
<input id="clan-tag" type="text" name="var" value="" />
<input id="clanSearchBtn" type="submit" name="submit" value="Submit">
</form>

I want to convert a post method form to curl command

I'm making an auto SMS system. But SMS provider gave me post method form but I want it to modify with curl command by my own.
they provided me
<head>
<title>SMS</title>
</head>
<body>
<form name="sms" method="post" >
<input type="text" placeholder="send to number" name="to" /><br />
<input type="textarea" placeholder="sms" name="msg" /><br />
<input type="submit" value=" OK " />
</form>
<?php
$apikey='$2y$10$t..Yr.YDG0kXYiuLwQ78OecDgz6/qh.1xSWx77mXjczkk3AEKvTZe';
if (isset($_POST["msg"]) ) {
$sendto = $_POST["to"];
$fullNumber = '880' . substr(preg_replace('/\D/', '', $sendto), -10);
$msg = urlencode($_POST["msg"]);
// $masking='CITY PORTER';
// $masking=urlencode($masking);
// masking $url='http://example.com/smsapi/masking?api_key='.$apikey.'&smsType=text&maskingID='.$masking.'&mobileNo='.$fullNumber.'&smsContent='.$msg.'';
$url='http://example.com/smsapi/non-masking?api_key='.$apikey.'&smsType=text&mobileNo='.$fullNumber.'&smsContent='.$msg.'';
if ( !empty($_POST["to"]) && !empty($_POST["msg"])) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL =>$url,
CURLOPT_USERAGENT =>'My Browser'
));
$resp = curl_exec($curl);
echo $resp;
curl_close($curl);
}
else
{ echo "Field is empty";}
}
?>
</body>
I converted it to curl command but this is not still working. I just want to input multiple value without is set() 1 value.
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row[mailing_no];
$message = "Dear Guardian, ". $row[name] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
Try this i hope your problem will be solve
<div id="send_reply"></div>
<form name="sms" method="post" >
<input type="text" placeholder="send to number" name="to" id="phone" /><br />
<input type="textarea" placeholder="sms" name="msg" id="mess" /><br />
<input type="submit" value=" OK " id="send_btn" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#send_btn").click(function(){
var txt1=$("#phone").val();
var txt2=$("#mess").val();
$.ajax({
url : 'check.php',
method : 'GET',
data : {txt1:txt1,txt2:txt2},
success:function(dda){
$("#send_reply").html(dda);
}
});
});
});
</script>
I think we were missing double quotes for $row keys, try this:
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row["mailing_no"];
$message = "Dear Guardian, ". $row["name"] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);

get response/result after submitting file to url

I'm trying to submit a file to a REST API url and need to get the response/result from this process. I'm trying to send it to another php and display the result but nothing. If it could display in the same php page then even better. How am i suppose to do that?
<?php
session_start();
// Start the session
$responseURL = "http://my-site.com/responseform.php";
$url = 'https://api-to-validate-file.com/api/validate';
$header = array('Content-Type: multipart/form-data','Authorization: apikey=0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f');
$fields = array('filename' => '#' . $_FILES['filename']['tmp_name'][0]);
$token = 'NfxoS9oGjA6MiArPtwg4aR3Cp4ygAbNA2uv6Gg4m';
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, $url);
curl_setopt($resource, CURLOPT_HTTPHEADER, $header);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($resource, CURLOPT_POST, true);
curl_setopt($resource, CURLOPT_POSTFIELDS, $fields);
curl_setopt($resource, CURLOPT_COOKIE, 'apiToken=' . $token);
$result = json_decode(curl_exec($resource));
///echo 'The body of the response is ' . $result;
curl_close($resource);
?>
<form method="post" action="index.php" enctype="multipart/form-data">
<input name="filename" type="file" />
<input type="submit" value="Upload" />
<input type="hidden" name="RespURL" value="<?= $responseURL ?>"><br>
</form>

curl and php html not logging in correcty i know curl functions work

I know my curl script works correctly. I can hardcode the email and pass in curl and it works fine, but now I am trying to create a php script to input it and it doesn't work. I will post links and code below.
I am using the input email#ccc.com:passss.
http://cyber-hosted.com/CH/index.html
<html>
<head>
</head>
<body>
<form action="n.php" method="post">
<input type="text" name="mail />
<input type="password" name="pass" />
</form>
</body>
http://cyber-hosted.com/CH/n.php
<?php
$usermail = $_POST['Mail'];
$pass = $_POST['pass'];
$url = "https://secure.tesco.com/register/default.aspx?vstore=0";
//
$h = curl_init();
curl_setopt($h, CURLOPT_URL, $url);
curl_setopt($h, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($h, CURLOPT_POST, true);
curl_setopt($h, CURLOPT_POSTFIELDS, "form=fSignin&from=https%3A%2F%2Fsecure.tesco.com%2Fclubcard%2Fmyaccount%2Fhome.aspx&formData=bmV3UmVnPWZhbHNlJg%3D%3D&loginID=$usermail&password=$pass&seamlesswebtag=&confirm-signin.x=47&confirm-signin.y=18");
curl_setopt($h, CURLOPT_HEADER, true);
curl_setopt($h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($h, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($h, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($h, CURLOPT_FOLLOWLOCATION, true);
//
$result = curl_exec($h);
echo $result;
?>
You typed mail with uppercase:
$usermail = $_POST['Mail'];
// here -----^
Change it to:
$usermail = $_POST['mail'];
Ah and I almost forgot the double quotes here:
<input type="text" name="mail />
<!-- here --------^ --->
It should be <input type="text" name="mail" />
Try giving the fields a value attribute
<input type="text" name="mail" value=""/>
<input type="password" name="pass" value=""/>
Also you are missing the submit button from your supplied code
<input type="submit" name="submit" value="Submit"/>
And finally you should URL encode the usermail and password parameters in the cURL request.

Categories