I just wanted to know if anyone knows how I can integrate a travel/deals API on my college project website.
I have looked at the Rome2Rio API and signed up and have the API key but I have no idea what i do next.Or if you think that is a hard one to use could you suggest an alternative easy one to integrate.
Any help would be great. I have added a link below to the documentation that might help you.
http://www.rome2rio.com/documentation/search
$url = 'http://<server>/api/1.4/json/Search?key=<key>&oName=Bern&dName=Zurich&noRideshare';
$content = file_get_contents($url);
$json = json_decode($content, true);
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($json));
foreach($iterator as $key => $value) {
echo "<p>$key => $value</p>";
}
Related
In my application need to find road type ie National Highway,By Pass Road using specific co-ordinates(13.094119, 80.198606).
I tried Google Place service and Geo-coding to find particular co-ordinates location details but many times it can't help me find out road type.
https://developers.google.com/places/web-service/
https://developers.google.com/maps/documentation/javascript/examples/geocoding-reverse
https://developers.google.com/maps/documentation/roads/speed-limits
$httpRequest = curl_init();
curl_setopt($httpRequest, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($httpRequest, CURLOPT_URL, "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=13.099765,%2080.162110&radius=500&type=Road&key=YOUR_KEY");
$result = curl_exec($httpRequest);
curl_close($httpRequest);
$result = json_decode($result,true);
foreach ($result['results'] as $key => $value) {
if(strpos($value['vicinity'],'High Road')!== false || strpos($value['vicinity'],'NH Road')!== false || strpos($value['vicinity'],'National Road')!== false){
echo $value['vicinity'];
}
}
Currently the Google Maps APIs don't expose this type of information in their responses. You can see the following feature requests in the Google issue tracker
Road Surface Type: https://issuetracker.google.com/issues/62535946
Access Details for Roads: https://issuetracker.google.com/issues/35829877
I believe these feature requests might be interesting for you. Feel free to star them to express your interest.
UPDATE
As a workaround try to use the snap to road of Roads API for your coordinate:
https://roads.googleapis.com/v1/snapToRoads?path=13.094119%2C%2080.198606&key=YOUR_API_KEY
This will provide the following response
{
"snappedPoints":[
{
"location":{
"latitude":13.094118495151756,
"longitude":80.19856816820958
},
"originalIndex":0,
"placeId":"ChIJ0dPfJw5kUjoR1sQRTkRxOIg"
}
]
}
From this response you can get the place ID of the road ChIJ0dPfJw5kUjoR1sQRTkRxOIg. Now use this place ID with geocoding service that gives you a road name at least:
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ0dPfJw5kUjoR1sQRTkRxOIg&key=YOUR_API_KEY
The same result in Geocoder tool:
https://google-developers.appspot.com/maps/documentation/utils/geocoder/#place_id%3DChIJ0dPfJw5kUjoR1sQRTkRxOIg
Hopefully the road name 'Grand Northern Trunk Road' gives a hint about its type.
I'm trying to get profile pictures using Instagram Api. I tried the following code:
function getpho($userid)
{
$userid = "000000";
$token = "my access token";
$url = "https://api.instagram.com/v1/users/".$userid."/?access_token=".$token;
$get = file_get_contents($url);
$json = json_decode($get);
foreach($json->data as $user)
{
return $user->profile_picture;
}
}
echo getpho($userid);
But this returns a blank page. What is wrong with my code?
try
$json = json_decode($get);
return $json->data->profile_picture;
Probably you're in Sandbox mode.
In this mode you can get media only of users that you've invited (up to 10). They will doesn't receive a notification, but they shall accept the request at this address: https://www.instagram.com/developer/clients/sandbox_invites/
By using this link you can get insta user details :
https://www.instagram.com/username/?__a=1&__d=dis
The SWF is located on a web server. I am calling the function using this code in AS3...
myPDF.save(Method.REMOTE, "http://www.example.com/generator/createpdf.php",
Download.ATTACHMENT, "line.pdf");
Here is my PHP script located on the server...
$method = $_GET['method'];
$name = $_GET['name'];
if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) {
// get bytearray
$pdf = $GLOBALS["HTTP_RAW_POST_DATA"];
// add headers for download dialog-box
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($pdf));
header('Content-disposition:'.$method.'; filename="'.$name.'"');
echo $pdf;
} else echo 'An error occured.';
It used to work, but stopped a while back. Any help would be greatly appreciated.
1) This stopped working for me as well, until I added the following -
if(!$HTTP_RAW_POST_DATA){
$HTTP_RAW_POST_DATA = file_get_contents(‘php://input’);
}
2) I also patched /src/org/alivepdf/pdf/PDF.as::save() per this post enter link description here
I am building a type of crm using ajax, php and mysql. I am building the solution with GET and POST requests using ajax xhr requests. My question is, what is the best way to make sure these requests are secure from any type of hack or attack. I want to make sure my clients data and this crm is secure.
Right now i am just using long hand ajax/javascript. I don't use much jquery: My request looks something like this:
function getContacts()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("div").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","xhr_php/getContacts.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var contact = document.getElementById('contact_id').value;
xmlhttp.send("contact="+contact);
}
my php file looks like this
$contact=$_POST['contact'];
$sql="SELECT *
FROM contacts
WHERE contacts.contact_id = $contact";
So this is the basic method i have used to not only retrieve data but also to insert records and run all other queries. My question is what is the best way to secure these requests and sql queries so that all the data is secure. I want to make sure this is a secure crm solution so that data can't be corrupted, stolen, injected, hacked, etc. Thank you for your help.
This is not secure; it is vulnerable to an SQL injection attack, which has nothing to do with Ajax, POST or GET. You should not be building SQL statements in that way. Your question isn't well suited to Stack Overflow - "How do I make my code secure" is a vast topic that can't be answered in a simple way. If you are building this in a professional capacity, please seek out a more senior developer to help you with this - if you are making basic SQL injection mistakes, then it is very unlikely you will be able to build an entire CRM package on your own while making it secure.
You should use PDO. Following is example code. you can modify it as required.
$host = 'localhost';
$dbname = 'contacts';
$username = 'anyuser';
$password = 'your password';
$conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//If contact is int value then pass it through intval function
$contact=intval($_POST['contact']);
$sql = 'SELECT * FROM contacts WHERE contacts.contact_id = :contact_id';
$statement = $conn->prepare($sql);
$statement->bindParam(':contact_id', $contact, PDO::PARAM_INT);
$statement->execute();
//Use $result is your page
$result = $statement->fetch(PDO::FETCH_ASSOC);
You can do insert / update with PDO as well
$stmt = $conn->prepare("INSERT INTO Table (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);
$stmt->execute();
Hope this helps.
This should be immune to sql injection:
$contact=intval($_POST['contact']);
$sql="SELECT *
FROM contacts
WHERE contacts.contact_id = $contact";
mysql_query($sql);
I am wondering how facebook has implemented the search functinality on the home page. as soon as i type 'a' the dropdown comes with the list of friends and its very very fast..
I saw in firebug that it sends a ajax request to one of its file.
I wanted to implement the same functionality in one of my webapp but even though my table has just 4 records it takes bit time to load the dropdown.
What i have done is
send ajax req with my search parameter
executed sql query
made the html
and returned it so it will
replace the div
Facebook has very expensive servers using a very expensive CDN (Akamai) and uses server-side caching like memcached.
If you can predict with reasonable accuracy the things the user might search for (e.g. a known friends and friends-of-friends list) and pre-cache them on the server you can do this quickly. If you deliver that list with the webpage in the first place and cache it on the client, it will be lightning fast (once the page is loaded anyway).
Try the following PHP code, it will crawl into the Fast Facebook Search site and echo the results. I hope it will be helpful, feel free to tweak it :)
<?php
function facebook_search_api($args, $referer = 'YOUR SITE ADDRESS', $endpoint = 'web')
{
$url = "http://www.FastFacebookSearch.com".$endpoint;
if ( !array_key_exists('v', $args) )
$args['v'] = '1.0';
//$args['key']="ABQIAAAArMTuM-CBxyWL0PYBLc7SuhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxT-uD75NXlWUsDRBw-8aVAlQ29oCg";
//$args['userip']=$_SERVER['REMOTE_ADDR'];
$args['rsz']='8';
$url .= '?'.http_build_query($args, '', '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$body = curl_exec($ch);
curl_close($ch);
//decode and return the response
return json_decode($body,true);
}
$query_temp=urldecode(isset($_GET['q'])?$_GET['q']:"none");
$search_type=urldecode(isset($_GET['search_engine'])?$_GET['search_engine']:"");
echo "$search_type Search Results for: $query_temp<br />-----<br />";
$query=$search_type.$query_temp;
$res = google_search_api(array('q' => $query));
$pages=$res['responseData']['cursor']['pages'];
$nres=0;
for($i=0;$i<count($pages);$i++)
{
$res = google_search_api(array('q' => $query,'start'=>$rez['responseData']['cursor']['pages'][$i]['start']));
for($j=0;$j<count($res['responseData']['results']); $j++)
{
$nres++;
echo urldecode("<a href=".$res['responseData']['results'][$j]['url'])."><big>";
echo urldecode($res['responseData']['results'][$j]['title'])."</a></big><br />";
echo urldecode("<font color=green><small>".$res['responseData']['results'][$j]['url'])."</small></font><br>";
echo urldecode("<iiisearch>".$res['responseData']['results'][$j]['content'])."<br><br>";
}
}
echo "<br />---<br />Total number of reuslts: $nres";
?>