I'm using the google admin api class to check for organization units. First level works, but second level fails. I've tried putting it in single quotes as per other posts, but still won't find it, and I get Yes No everytime. This seems to have started happening about two months ago. Anything that would have changed?
// This returns all of them
//$units = $google_client->getOrgUnits('my_customer', ["type" => "ALL"]);
if ($google_client->OrgUnitExists('my_customer', "A")) {
echo "Yes\r\n";
if ($google_client->OrgUnitExists('my_customer', "A/B")) {
echo "Yes\r\n";
}
else {
echo "No\r\n";
}
}
else {
echo "No\r\n";
}
According to the documenation for the orgunits.get request:
orgUnitPath > The full path of the organizational unit or its unique ID.
From the description of your question it looks like you are not supplying an accurate path to the request, hence the "Yes No" response.
Instead, you can also pass the id of the organization unit.
Reference
Directory API orgunits.get.
Related
I am building my wedding website and want to integrate an RSVP form using Gravity Forms. The issue I am running into is how to set certain guest that have +1's. I would like to show an additional guest entry (First Name, Last Name, Meal Option) when the initial First Name and Last Name has been populated. How would I go about doing this? Any help would be great! Thanks in advance!
Here is how I'd solve this problem:
First, you need to put everything in the DB, the easiest way would be to either do it manually or somehow loop through an array/CSV calling add_option($key, $value) Again, I would recommend a mobile/phone number as they'll be unique so you don't pull the wrong "John Smith". I'll assume you'll keep it basic with $key as the unique identifier and $value as boolean as to whether to show additional info. Interestingly, by default, if not found get_option($key) will return false and therefore not show your additional data, which I would assume you'd want anyway. If you'd rather it return true just pass true as the second argument.
Now for your answer:
Your URL is something like https://somesite.com/rsvp?id=1234.
function allowed_plus_one() {
$id = $_GET["id"];
$allowed = get_option($id);
return $allowed;
}
Then assumedly it'll be something like
if (allowed_plus_one()) {
// show form with plus one
} else {
// show form without
}
EDIT:
Keeping separate incase this has already been viewed.
You should also be checking for the existence of $_GET["id"] and behaving accordingly. eg:
if (isset($_GET["id"] && !empty($_GET["id"]) {
//do logic above
} else {
//here by mistake so don't show any form?
}
This question already has answers here:
How do I run a WHOIS lookup with PHP or Python?
(7 answers)
Closed 6 years ago.
I am looking for a fast wat to test if a domain name is in use, hence has a site attached to it. I have a huge list of domain names and need to check which ones have a site attached to it or not.
If I know that there is a site attached to it then I don't need to do any time consuming whois lookups, etc.
My initial idea was to check for HTTP header code and see if the header codes return 200, 301, 302... if is is something else there is a high chance that there is no site attached or that the domain name is available. The code snipper I am using is:
$headers = #get_headers( $url);
$headers = (is_array($headers)) ? implode( "\n ", $headers) : $headers;
return (bool)preg_match('#^HTTP/.*\s+[(200|301|302)]+\s#i', $headers);
However this process is pretty slow.
Next I've tried using the PHP function checkdnsrr to check if a DNS record exist. I am using the following code snipper.
if (checkdnsrr($domain . ".", "A") == false) {
echo "Domain might be available";
} else {
echo "Domain is in use";
}
Unfortunately it gives me a lot of "false" information saying that the domain might be available. The same goes for the following code snippet:
if (gethostbyname($domain) != $domain) {
echo "DNS Record found";
} else {
echo "NO DNS Record found";
}
A WHOIS lookup is a possibility also however with all the new TLD (.frl, .xyz, etc.) this might be a huge task to setup.
Another idea I had was to ping the domain name in question and if I get a response I know the domain name is "in use". Not sure if this is the best approach therefor I am asking you is there a a fast but more reliable way to check if domain is in use (or registered)?
You could try parse "http://whois.domaintools.com/" . $domain
and look for the keyword "Domain Available"
We're interested about using Google Custom Search / Google in our project, mostly due to the fact that it's amazing at conjugation & correcting misspelled words.
We know that it can return data in JSON or XML, and we're fine with that. But finding an answer to question:
Can we use that conjugation and mistake correction and search our own database/api?
If you would type drnks with no alcohol it would automatically correct to drinks with no alcohol, and then search our database like this:
http://example.com?search=drinks&alcohol=0, and it could respond like this:
{
"coke": {
"alcohol": 0,
"calories": 300,
"taste": "awesome"
},
"pepsi": {
"alcohol": 0,
"calories": 300,
"taste": "meh"
}
}
And then it would return these two results, in some form.
Solutions using the paid version are fine.
If it's possible to do this, could you provide me with a simple example?
Google provides a REST API for their custom search, you can query it from your server to determine whether there is a better spelling for the search terms or not, and then use that to query your internal database.
In my code I'm using Guzzle, a REST client library to avoid suffering with cURL's ugly and verbose code, but feel free to use cURL if you really need to.
// Composer's autoloader to load the REST client library
require "vendor/autoload.php";
$api_key = "..."; // Google API key, looks like random text
$search_engine = "..."; // search engine ID, looks like "<numbers>:<text>"
$query = "drnks with no alcohol"; // the original search query
// REST client object with some defaults
// avoids specifying them each time we make a request
$client = new GuzzleHttp\Client(["base_url" => "https://www.googleapis.com", "defaults" => ["query" => ["key" => $api_key, "cx" => $search_engine, "fields" => "spelling(correctedQuery)"]]]);
try {
// the actual request, with the search query
$resp = $client->get("/customsearch/v1", ["query" => ["q" => $query]])->json();
// whether Google suggests an alternative spelling
if (isset($resp["spelling"]["correctedQuery"])) {
$correctedQuery = $resp["spelling"]["correctedQuery"];
// now use that corrected spelling to query your internal DB
// or do anything else really, the query is yours now
echo $correctedQuery;
} else {
// Google doesn't have any corrections, use the original query then
echo "No corrections found";
}
} catch (GuzzleHttp\Exception\TransferException $e) {
// Something bad happened, log the exception but act as if
// nothing is wrong and process the user's original query
echo "Something bad happened";
}
Here are some instructions to obtain your API key, and the custom search engine ID can be obtained from the control panel.
If you look carefully you can see I've specified the fields query parameter to request a partial response with only the eventual spelling suggestions, to (hopefully) get better performance as we don't need anything else from the response (but feel free to change/remove it if you do need the complete response).
Note that Google has no clue about what's in your database so the spelling corrections will only be based on the public data Google has about your website, I don't think there is a way to make Google know about your internal DB, not that it's a good idea anyway.
Finally, make sure to handle rate-limits and API failures gracefully by still giving the user the possibility to search using their original query (just act like nothing wrong happened, and only log the error for later review).
I am building a website where I need to retrieve Facebook shares and likes of numerous links and URLs from different sites.
The problem is, for some URLs it is impossible to get what I wanted. For example, when I look for data about links that look like http://www.example.com/?a=1&b=2&c=3 all I get is wrong data about http://www.example.com/?a=1 and the rest of the URL (&b=2&c=3) is simply ignored by Facebook.
Here at StackOverflow, a lot of people are looking for an answer and many questions are simply unanswered. So, once I did it right, I'm back to tell how I did it.
P.S. : This works only for non-Facebook URLs. If you're looking for shares and likes counts of an internal Facebook link (image, video ...), this won't work for you. I'll be using PHP to answer the question.
To get likes and shares counts, I use FQL instead of the Graph API (even though I am actually using the Graph API to send the query).
But this is not enough : to be able to do so, I had call the rawurlencode() function on the URL I want to get data about. Otherwise, I'll keep getting errors.
So, this likes(), the function I am using to have the counts :
function likes($url) {
$url = rawurlencode($url);
$json_string = file_get_contents("http://graph.facebook.com/fql?format=json&q=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url='$url'");
$json = json_decode($json_string, true);
if (key_exists("data", $json)) {
if (is_array($json["data"])) {
if (array_key_exists("0", $json["data"])) {
return intval($json["data"]["0"]["share_count"]) + intval($json["data"]["0"]["like_count"]);
} else {
echo "Error : '0' is no key<br/>";
return 0;
}
} else {
echo "Error : data is no table <br/>";
return 0;
}
} else {
echo "Error : No data key <br/>";
return 0;
}
}
I hope this will help someone someday :)
I want to have a form on my intranet site... basically we are a home improvement company and have a list of bad area codes that we do not do business in ... IE list of bad zips 19020 19021 etc are bad so if they are I want it to return with a popup which says bad area ... if it is not on the list I want it to say Good Area
You haven't given too much information, so what follows is a very general solution. One way to approach this is to have two maps called badZips and goodZips:
var badZips = {
"19020": true,
"19021": true
...
};
var goodZips = {
"90210": true,
...
};
Then in your form-validation function, you can do:
if(badZips[zip]) {
alert("You entered a bad zip code");
}
else if(goodZips[zip]) {
alert("You entered a good zip code");
}
else {
alert("That zip code is not recognized");
}
Actually creating the maps depends on how your webapp is set up. How do you store the zips - is it in the database? Or have you hardcoded it?
Using apache, install geoIP. Echo their zipcode into a javascript function, which compares to a black-list you created.
http://www.maxmind.com/app/ip-location
Your functional requirements are pretty simple but you didn't really mention what setup you have. Do you want this functionality to happen on a form? What are you going to code with? Do you have a database? Based on the tags you've used I'll just assume that you don't have a database.
Basically you can have a list of area codes and a flag for each to indicate if it's a bad or a good code. You can keep this list in a multi-dimensional array in PHP as static data (http://www.webcheatsheet.com/PHP/multidimensional_arrays.php).
So it might look something like:
<?php
$areaCodes = array( array('aCode'='19020','aFlag'=>true),
array('aCode'='19021','aFlag'=>true),
array('aCode'='19022','aFlag'=>false)
);
?>
When you need an area code to be validated, just do a search in the array and check the flag to see if it's a good code or a bad code.
Store the zip codes in an array, then check if the given zip is in the array.
<?php
$BadZip = array("19020", "19021");
if (in_array($Zip, $BadZip))
{
echo "Bad Zip code!";
}
?>
If in_array returns true, then the zip code is in the list of bad zips.
Alternatively you could use the same method with a list of good zips.