I have a username and password, yet trying to send a request to SOAP web server via WSDL while using Authentication, it gives an error Username was not specified.
What am I doing wrong? Thanks in advance
<?php
require_once('lib/nusoap.php');
$username = 'user';
$password = 'pass';
$proxyhost = isset($_POST['proxyhost']) ? $_POST['proxyhost'] : '';
$proxyport = isset($_POST['proxyport']) ? $_POST['proxyport'] : '';
$proxyusername = isset($_POST['proxyusername']) ? $_POST['proxyusername'] : '';
$proxypassword = isset($_POST['proxypassword']) ? $_POST['proxypassword'] : '';
$useCURL = isset($_POST['usecurl']) ? $_POST['usecurl'] : '0';
//echo 'You must set your username and password in the source';
//exit();
$client = new nusoap_client("example.com:88/Service.asmx?wsdl", 'wsdl',
$proxyhost, $proxyport, $proxyusername, $proxypassword);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$client->setUseCurl($useCURL);
$client->loadWSDL();
$client->setCredentials($username, $password, 'digest');
$result = $client->call('GetValidTourList', array());
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
$err = $client->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
echo '<h2>Request</h2><pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2><pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
?>
Related
I have a good result using PDO query retrieve all data from database.
But, this only display the result with LIMIT like 10.
My questions now is how to paste this result for paginate?
I want to set result for 10 perpage and have prev 1 2 3 4 next for all data.
below script is good and fast result for me.
<?php
//load database connection
$host = "localhost";
$user = "root";
$password = "";
$database_name = "";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
// Search from MySQL database table
$search=$_POST['search'];
$query = $pdo->prepare("select * from table where colum1 LIKE '%$search%' OR colum2 LIKE '%$search%' LIMIT 0 , 10");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();
// Display search result
if (!$query->rowCount() == 0) {
echo "Search found :<br/>";
echo "<table style=\"font-family:arial;color:#333333;\">";
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Title Books</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Author</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Price</td></tr>";
while ($results = $query->fetch()) {
echo "<tr><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['name'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo $results['description'];
echo "</td><td style=\"border-style:solid;border-width:1px;border-color:#98bf21;\">";
echo "$".$results['thumb'];
echo "</td></tr>";
}
echo "</table>";
} else {
echo 'Nothing found';
}
?>
I would suggest that you create a class for pagination then include the class.
pagination.php
<?php
class paginate
{
private $pdo;
function __construct($pdo)
{
$this->db = $pdo;
}
public function dataview($query,$Search)
{
$stmt = $this->db->prepare($query);
$stmt->execute(arary($Search,$Search));
$results = $stmt->fetchall();
if (count($results) > 0) {?>
Search found : <br/>
<table style="font-family:arial;color:#333333;">";
<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Title Books</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;">Author</td><td style="border-style:solid;border-width:1px;border-color:#98bf21;background:#98bf21;\">Price</td></tr>
<?php
foreach ($results as $row):
?>
<tr><td style="border-style:solid;border-width:1px;border-color:#98bf21;">
<?php echo $row['name'];?></td>
<td style="border-style:solid;border-width:1px;border-color:#98bf21;">;
<?php echo $row['description'];?>
</td>
<td style="border-style:solid;border-width:1px;border-color:#98bf21;">
<?php echo $row['thumb'];?>
</td></tr>
<?php
endforeach;
echo "</table>";
} else {
echo "<p> Nothing found </p>";
}
}
public function paging($query, $records_per_page)
{
$starting_position = 0;
if (isset($_GET['page_no'])) {
$starting_position = ($_GET["page_no"] - 1) * $records_per_page;
}
$query2 = $query . " limit $starting_position,$records_per_page";
return $query2;
}
public function paginglink($query, $records_per_page)
{
$self = $_SERVER['PHP_SELF'];
$stmt = $this->db->prepare($query);
$stmt->execute();
$total_no_of_records = $stmt->rowCount();
if ($total_no_of_records > 0) {
?>
<ul class="pagination"><?php
$total_no_of_pages = ceil($total_no_of_records / $records_per_page);
$current_page = 1;
if (isset($_GET["page_no"])) {
$current_page = $_GET["page_no"];
}
if ($current_page != 1) {
$previous = $current_page - 1;
echo "<li><a href='" . $self . "?page_no=1' >First</a></li>";
echo "<li><a href='" . $self . "?page_no=" . $previous . "'>Previous</a></li>";
}
for ($i = 1; $i <= $total_no_of_pages; $i++) {
if ($i == $current_page) {
echo "<li class='active'><a href='" . $self . "?page_no=" . $i . "' >" . $i . "</a></li>";
} else {
echo "<li><a href='" . $self . "?page_no=" . $i . "'>" . $i . "</a></li>";
}
}
if ($current_page != $total_no_of_pages) {
$next = $current_page + 1;
echo "<li><a href='" . $self . "?page_no=" . $next . "'>Next</a></li>";
echo "<li><a href='" . $self . "?page_no=" . $total_no_of_pages . "'>Last</a></li>";
}
?></ul>
<?php
}
}
}
?>
page.php
<?php
//your connection
$host = "localhost";
$user = "root";
$password = "";
$database_name = "";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
include_once'pagination.php';
$paginate = new paginate($pdo);
$search=$_POST['search'];
$Search = "%$search%";
$query = "SELECT * from table where colum1 LIKE ? OR colum2 LIKE ? ";
$records_per_page=10;
$newquery = $paginate->paging($query,$records_per_page,$Search);
$paginate->dataview($newquery,$Search);
$paginate->paginglink($query,$records_per_page);
?>
This should work. Suggestions/comments are welcome.
This is one of the projects I have used the above code to do a pagination :
or use jquery dataTables which will also work perfect
all u need is to download https://datatables.net/
With Datatables, simple download it then add required scripts and css, then on your table add an ID, then initialize datatable
$('#TableID').dataTable();
You might have to do the proper table markup,
<table>
<thead>
<tr>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td>Text</td>
</tr>
</tbody>
Sorry , I have a problem with this script :
It's for get tweet with specific id ;
$tweetlist = $twitter->get('https://api.twitter.com/1.1/statuses/show.json?id=694658584664236033');
foreach ($tweetlist->statuses as $key => $value) {
$message = utf8_decode($value->text);
echo $message;
}
Warning: Invalid argument supplied for foreach()
Thank you so much for your help
Nicolas
remove ->statuses, like:
$tweetlist = $twitter->get('https://api.twitter.com/1.1/statuses/show.json?id=694658584664236033');
foreach ($tweetlist as $key => $value) {
$message = utf8_decode($value->text);
echo $message;
}
I read this section http://quickblox.com/developers/Social_Networks_Integration_Manual
But I don't know what to do.If somebody know please help me :)
I was tried with hybridauth I have connection with facebook (my API) hybridauth return to me user information.I create user in quickblox with random password and facebook email and simulate login but this is bad because quickblox in this way don't return to me token and if I want to edit profil I can't....
if( isset( $_GET["login"] ) ){
try{
$hybridauth = new Hybrid_Auth( $config );
$adapter = $hybridauth->authenticate( "facebook" );
$user_profile = $adapter->getUserProfile();
}
catch( Exception $e ){
die( "<b>got an error!</b> " . $e->getMessage() );
}
$token = $adapter->getAccessToken();
//$token['access_token'];
$nonce = rand();
$timestamp = time();
$signature_string = "application_id=".APPLICATION_ID."&auth_key=".AUTH_KEY."&nonce=".$nonce."×tamp=".$timestamp;
$signature = hash_hmac('sha1', $signature_string , AUTH_SECRET);
// Build post body
//$post_body = "application_id=" . APPLICATION_ID . "&auth_key=".AUTH_KEY."×tamp=".$timestamp."&nonce=".$nonce."&signature=".$signature."&user[email]=" . $user_profile->email . "&provider=facebook&scope=friends_status,read_mailbox,photo_upload&keys[token]=".$token['access_token'];
$post_body = http_build_query(array(
'application_id' => APPLICATION_ID,
'auth_key' => AUTH_KEY,
'timestamp' => $timestamp,
'nonce' => $nonce,
'signature' => $signature
));
$post_body = "application_id=" . APPLICATION_ID . "&auth_key=" . AUTH_KEY . "×tamp=" . $timestamp . "&nonce=" . $nonce . "&signature=" . $signature."&user[login]=&user[email]=&user[password]=&provider=facebook&scope=friends_status,read_mailbox,photo_upload&keys[token]=".$token['access_token']."&keys[secret]=";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT . '/' . QB_PATH_SESSION); // Full path is - https://api.quickblox.com/session.json
curl_setopt($curl, CURLOPT_POST, true); // Use POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body); // Setup post body
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Receive server response
$response = curl_exec($curl);
dump($response);
if ($response) {
return $response . "\n";
} else {
$error = curl_error($curl). '(' .curl_errno($curl). ')';
return $error . "\n";
}
This don't work...this is shity they don't have examples :O
You should add 'provider=facebook' to your post_body and signature_string
After this - QuickBlox will return HTML page with Facebook login dialog, which you should render to your end users
Hi I am new to FatSecret Platform API and i developed a PHP script to access food details using foods.search method Here is the foods.search method Api call example,used Curl and works perfect. <?php $consumer_key = "xxxxxxx"; $secret_key = "xxxxxxx"; //Signature Base String //<HTTP Method>&<Request URL>&<Normalized Parameters> $base = rawurlencode("GET")."&"; $base .= "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver. api&"; //sort params by abc....necessary to build a correct unique signature $params = "method=foods.search&"; $params .= "oauth_consumer_key=$consumer_key&"; // ur consumer key $params .= "oauth_nonce=123&"; $params .= "oauth_signature_method=HMAC-SHA1&"; $params .= "oauth_timestamp=".time()."&"; $params .= "oauth_version=1.0&"; $params .= "search_expression=".urlencode($_GET['pasVar']); $params2 = rawurlencode($params); $base .= $params2; //encrypt it! $sig= base64_encode(hash_hmac('sha1', $base, "$secret_key&", true)); // replace xxx with Consumer Secret //now get the search results and write them down $url = "http://platform.fatsecret.com/rest/server.api?". $params."&oauth_signature=".rawurlencode($sig); //$food_feed = file_get_contents($url); list($output,$error,$info) = loadFoods($url); echo '<pre>'; if($error == 0){ if($info['http_code'] == '200') echo $output; else die('Status INFO : '.$info['http_code']); } else die('Status ERROR : '.$error); function loadFoods($url) { // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, $url); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); $error = curl_error($ch); $info = curl_getinfo($ch); // close curl resource to free up system resources curl_close($ch); return array($output,$error,$info); } ?> the above script working perfect and retrieves food details using search method.But when i use food.get method to retrieve data using food_id it says invalid signature error,Here's the food.get method api call example,I have given correct keys and passed food_id parameter.Can someone help me to solve the issue,I am really struck on this code.It says invalid signature error. <?php $consumer_key = "xxxxxxxxx"; $secret_key = "xxxxxxxxxx"; //Signature Base String //<HTTP Method>&<Request URL>&<Normalized Parameters> $base = rawurlencode("GET")."&"; $base .= "http%3A%2F%2Fplatform.fatsecret.com%2Frest%2Fserver.api&"; //sort params by abc....necessary to build a correct unique signature $params = "method=food.get&"; $params .= "oauth_consumer_key=$consumer_key&"; // ur consumer key $params .= "oauth_nonce=".rand()."&"; $params .= "oauth_signature_method=HMAC-SHA1&"; $params .= "oauth_timestamp=".time()."&"; $params .= "oauth_version=1.0&"; $params .= "food_id=".urlencode($_GET['pasVar']); $params2 = rawurlencode($params); $base .= $params2; //encrypt it! $sig= base64_encode(hash_hmac('sha1', $base, "$secret_key&", true)); // replace xxx with Consumer Secret //now get the search results and write them down $url = "http://platform.fatsecret.com/rest/server.api?". $params."&oauth_signature=".rawurlencode($sig); //$food_feed = file_get_contents($url); list($output,$error,$info) = loadFoods($url); echo '<pre>'; if($error == 0){ if($info['http_code'] == '200') echo $output; else die('Status INFO : '.$info['http_code']); } else die('Status ERROR : '.$error); function loadFoods($url) { // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, $url); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); $error = curl_error($ch); $info = curl_getinfo($ch); // close curl resource to free up system resources curl_close($ch); return array($output,$error,$info); } ?> Help me what's the error in the code and help me to solve the issue as i have to use this API in my project Thanks waiting for your replies....
You should order you params by alpha.
So you should do it in this order:
$params = "food_id=".urlencode($_GET['pasVar'])."&";
$params .= "method=food.get&";
$params .= "oauth_consumer_key=$consumer_key&"; // ur consumer key
$params .= "oauth_nonce=".rand()."&";
$params .= "oauth_signature_method=HMAC-SHA1&";
$params .= "oauth_timestamp=".time()."&";
$params .= "oauth_version=1.0";
I am wondering, how can I access a file outside the root directory of my server?
For example, /home/username/FILE.mp3
The code i am currently using to open a file is the following:
<?php
$location = "ABSOLUTE-PATH/FILE.mp3";
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
$data = curl_exec($ch);
$timestamp = curl_getinfo($ch, CURLINFO_FILETIME);
curl_close($ch);
if ($data === false) {
echo 'CURL Failed';
exit;
}
//Get file size
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$contentLength = (int)$matches[1];
}
$begin = 0;
$end = $contentLength - 1;
if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches))
{
$begin = intval($matches[1]);
if (!empty($matches[2]))
{
$end = intval($matches[2]);
}
}
if (isset($_SERVER['HTTP_RANGE']))
{ header('HTTP/1.1 206 Partial Content'); }
else
{ header('HTTP/1.1 200 OK'); }
header('Accept-Ranges: bytes');
header('Content-Length: ' . $contentLength);
header("Content-Range: bytes $begin-$end/$contentLength");
header('Content-Type: audio/mpeg');
header('Cache-Control: public, must-revalidate, max-age=0');
if ($timestamp != -1) { //otherwise unknown
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $timestamp) . " GMT");
}
ob_clean();
flush();
echo ($data);
exit;
?>
I know as a fact that cURL doesn't work with relative paths and i assume that a file outside the root directory is treated as a relative link.
Why would you use cURL? Typically cURL would be something you would use to communicate with a different server via HTTP. Why not use file, file_get_contents, fopen or similar?