This question already has answers here:
apache & php 500 error nightmares
(1 answer)
php return 500 error but no error log
(12 answers)
Closed 5 years ago.
<?php
if(isset($_POST['ccode']) && isset($_POST['mobile'])){
// Authorisation details.
$username = "stravin123#gmail.com";
$hash = "eb88119d3e9cdc20634c62f6493644ff94dec1b60597f68459becfb7ae0a7e96";
// Config variables. Consult http://api.txtlocal.com/docs for more info.
$test = "0";
// Data for text message. This is the text message data.
$sender = "Visitor Management Team"; // This is who the message appears to be from.
$numbers = $_POST ['ccode'].$_POST['mobile']; // A single number or a comma-seperated list of numbers
$message = $_POST['msg'];
// 612 chars or less
// A single number or a comma-seperated list of numbers
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.txtlocal.com/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); // This is the result from the API
if($result ==true){
echo "Message has been sent";
curl_close($ch);
}
?>
This is my php code. Whenever I try to access it, it keep showing HTTP ERROR 500. I am currently using hostinger. Please help. Thanks in advance
Related
$username = "info#example.com";
$hash = "*******************************************";
$test = "0";
$sender = "php sender";
$numbers = "7575757577";
$message = "verification code";
$message = urlencode($message);
$data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
$ch = curl_init('http://api.textlocal.in/send/?');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo"<pre>";
print_r($result);exit;
I am implementing free SMS API with CodeIgniter. Now, problem is that when I click on submit button it throws an error as mention below
{"errors":[{"code":3,"message":"Invalid login details"}],"status":"failure"}
I have no idea why it throwing this error. How can I implement this with CodeIgniter? I have also load curl library in autoload file. Please help me.
Thank You
I found a php class on the textlocal.in api documentation. Download that file and upload it to your site. Here is the download link; click.
Then just use this simple code to send a sms;
require 'textlocal.class.php';
$textlocal=new textlocal('me#textlocal.in','e215398a8820abd2c7a11a6cd5b1009d'); // email and hash
$textlocal->sendSms(['917788990011'],'Your car - KA01 HG 9999 - is due for service on July 24th, please text SERVICE to 92205 92205 for a callback','FORDIN'); // First target phone number, then the message, and then where the sms comes from
(Got the code from here; click)
If you have anymore questions, just ask :)
I am using a sms gateway i.e. sms4connect. Sms are sending successfully. Now the problem is I want to save the sms sending results into my table and then fetch the results.
Here is my php code :
<?php
$num = "92xxxxxxxxxx";
$mes = "Hello World (&) and a 5 note";
// Configuration variables
$type = "xml";
$id = "myid";
$pass = "mypass";
$lang = "English";
$mask = "mymask";
// Data for text message
$to = $num ;
$message = $mes;
$message = urlencode($message);
// Prepare data for POST request
$data = "id=".$id."&pass=".$pass."&msg=".$message."&to=".$to."&lang=".$lang."&mask=".$mask."&type=".$type;
// Send the POST request with cURL
$ch = curl_init('http://www.sms4connect.com/api/sendsms.php/sendsms/url');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); //This is the result from SMS4CONNECT curl_close($ch);
echo $result;
$query = mysql_query("INSERT INTO sms_response (phone, msg) values('$to','$result')");
?>
and I am getting the message "(300 Success Message Sent to Telecom. 239133150)". I want to save this message against each number into my database table. As you see in my PHP code that I am inserting $to, $result values in sms_response table but instead of saving number and message, I am getting these values in my table as shown in the image.
So How can I save message and Phone into my table correctly. Help would be highly appreciable.
You can create an XML object by this script
$xml=simplexml_load_string($result) or die("Error: Cannot create object");
print_r($xml);
In $xml you will get all the data fetched from the sms gateway. Which you can retrieve and save in DB.
simplexml_load_string it creates XML object from given XML string.
If you are getting a success message in node in your XML, you can simply retrieve the data like
$successMessage = $xml->message;
Save this $successMessage message in your db column. Please replace message with related field in your XML response. This is just an example.
Update
To store a phone number along with message you can concat them like
$successMessage = $num.": ".$xml->message;
This is just an example. You can concat them in any format. While retrieving the message if you want to get the phone number from the message you can explode the string by ":"
$msg = explode(":",$message_column);
echo $msg[0]; //phone number
echo $msg[1]; //message
I am integrating SMS gateway for the very first time. I want to send sms when someone pays to the website. I am using the following code:
<?php
$pay="1000";
$msg="Arivind";
echo $url="http://yourdomainname.com/api/swsend.asp?username=xxxxxx&password=xxxxxx&sender=SENDERID&sendto=91XXXXXXXXX&message=Dear'$msg' Thanks for making payment of Rs '$pay'";
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_URL,$url);
$contents=curl_exec($c);
curl_close($c);
echo "SMS Successfully sent";
?>
Now if i am using variable in body of message, the message is not sent but if i use static message the message is getting delivered to the number.
The static message doesnt solve my purpose as i need the message to be sent to different person, the variable used ie $msg will have different name of people & fetched from database.
KINDLY SUGGEST.
Using variables between single quotes ' does not convert it into dynamic values. Also its better to RestApi in simple PHP function:
function CURLcall($number, $message_body){
$api_params = "swsend.asp?username=xxxxxx&password=xxxxxx&sender=SENDERID&sendto=91XXXXXXXXX&message=$message_body";
$smsGatewayUrl = "echo $url="http://yourdomainname.com/api/";
$smsgatewaydata = $smsGatewayUrl.$api_params;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, smsgatewaydata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
// Use file get contents when CURL is not installed on server.
if(!$output){
$output = file_get_contents($smsgatewaydata);
}
}
Call above function as:
$message_body = urlencode("Dear $msg Thanks for making payment of Rs $pay");
CURLcall('918954xxxxx',$message_body);
Please note: urlencode is useful to avoid errors in GET method as it convert space into encoded format http://php.net/manual/en/function.urlencode.php
You can also use http_build_query to convert your variables into a nicely formatted URL.
<?php
$fname = 'Matthew';
$lname = 'Douglas';
$amount = 1000;
$message = "Thanks for your payment of Rs {$amount}.";
$urlComponents = array(
'firstName' => $fname,
'lastName' => $lname,
'message' => $message
);
$url = 'http://yourdomainname.com/api/swsend.asp?';
echo $url . http_build_query($urlComponents);
?>
This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 7 years ago.
I have this block of text (from the Discogs API) detailing information about bands that contain the word "Pink"...
http://pastebin.com/3vBnC0aE
I'm trying to figure out how to correctly extract the artist names from this block of text. My attempt was:
<?php
$url = "https://api.discogs.com/database/search?type=artist&q=pink"; // add the resource info to the url. Ex. releases/1
//initialize the session
$ch = curl_init();
//Set the User-Agent Identifier
curl_setopt($ch, CURLOPT_USERAGENT, 'YourSite/0.1 +http://your-site-here.com');
//Set the URL of the page or file to download.
curl_setopt($ch, CURLOPT_URL, $url);
//Ask cURL to return the contents in a variable instead of simply echoing them
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Execute the curl session
$output = curl_exec($ch);
//close the session
curl_close ($ch);
function textParser($text, $css_block_name){
$end_pattern = '], "';
switch($css_block_name){
# Add your pattern here to grab any specific block of text
case 'title';
$end_pattern = '", "';
break;
}
# Name of the block to find
$needle = "\"{$css_block_name}\":";
# Find start position to grab text
$start_position = stripos($text, $needle) + strlen($needle);
$text_portion = substr($text, $start_position, stripos($text, $end_pattern, $start_position) - $start_position + 1);
$text_portion = str_ireplace("[", "", $text_portion);
$text_portion = str_ireplace("]", "", $text_portion);
return $text_portion;
}
$blockTitle = textParser($output, 'title');
echo $blockTitle. '<br/>';
?>
but that's giving this error:
Warning: stripos(): Offset not contained in string in C:\xampp\htdocs\WellItsFixed3\TTpage1.php on line 41
Line 41 is
$text_portion = substr($text, $start_position, stripos($text, $end_pattern, $start_position) - $start_position + 1);
The ultimate goal is to be able to present the extracted band titles in a list.
Any insight appreciated. Thank you.
This is clearly a JSON encoded string and you are overshooting with your approach. Just do:
$data = json_decode($your_string);
and $data will contain all the info in a structured way, see the json_decode() manual for more details.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Parse Json in php
Im using an API to CURL a submitted user image to a remote server, the response is in JSON and I'm not sure how to parse it.
Here is my php CURL file
<?php
$api_key = 'xxxxxx';
$api_secret = 'xxxxx';
$Dirty_uid = $_GET['uid'];
$uid = htmlentities($Dirty_uid);
$Dirty_img = $_GET['img'];
$img = htmlentities($Dirty_img);
$query2 = 'http://rekognition.com/func/api/?api_key='.$api_key.'&api_secret='.$api_secret.'&jobs=face_recognize&urls='.$img.'&name_space=xxx&user_id=xxx';
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_URL, $query2); // get the url contents
$data2 = curl_exec($ch2); // execute curl request
curl_close($ch2);
$json2 = json_decode($data2);
print_r($json2)
?>
and here is a sample of the JSON data that comes back (Generic)
Code:
{
url: "http://farm3.static.flickr.com/2566/3896283279_0209be7a67.jpg",
face_detection: [
{
boundingbox:
{
tl: {
x: 50,
y: 118
},
size:{
width:232;
height:232;
}
}
name: "mona_lisa:0.92,barack_obama:0.02,mark_zuckerberg:0.01,"
}
]
usage: {
status: "success",
quota: 999,
api_id: "xxx"
}
}
Where the json string says "name" I need my script to only print the username if the number (after the : is higher then a threshold (lets say .70 for now).
How do I do this? I've worked with XML api's before and returning the data was simple with a
Code:
$xml = simplexml_load_string($data);
type thing.
You already have most of it. You have json_decodeed the result. Now you just need to access the data like
$name = $json2->face_detection[0]->name