loading
Please wait while loading...

Read more Google Oauth 2.0 ask permission every time

I have made a application using google account for login. Reference to google's example, it's easy make the login work well. However, I'm face to a serious problem that google ask for permission approval every time. For a openid login, like facebook, we will ask permission in the first time only and for the next time, it should automatically complete the login and no need to approve by user again. For this purpose, I search from the internet and finally found the solution as following:

To make the application just ask permission for once, add the following line in the config

$client->setApprovalPrompt(auto);
...........

Read more How to add application to facebook fans page

Easily use the following url to add your app to any fans page you have manage right.

http://facebook.com/add.php?api_key=[YOUR_APP_KEY]&pages=1&page=[YOUR_PAGE_ID]

Read more Verify email address by PHP filter_var

To check an email address is valid or not, we always use preg_match. Today I found that php5 has already allow a function to do so, which is filter_var

filter_var($email, FILTER_VALIDATE_EMAIL)

However, most checking script include filter_var doesn't well checking the domain part. For example, an email xxx@xxx.com1 can pass the validation but .com1 is a invalid domain name, so I add some code to the function to imporve the function as below.

function verifyEmail($email) {
	if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
		return preg_match('/^([a-z]{2,4})$/', end(explode('.',$email)));
	}
	return false;
}

Note: I have set 2-4 letter in the last part of the domain, but you may know there exists some special domain will not pass the validation (such as .travel, .museum)

filter_var also allow some more checking function, such as FILTER_VALIDATE_URL, FILTER_VALIDATE_IP, you may read detail on php.net

Read more JOIN table by varchar fields - Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_genera

Usually, we will using integer fields to join two table, however, today I have a case need to use a varchar field to join the tables and then get the error "Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation", search the error on google and finally I got the solution as below

SELECT a.* FROM a INNER JOIN b ON CAST(a.field AS CHAR) = CAST(b.field AS CHAR)

Read more Detect browser support HTML5 drag and drop by javascript

if('draggable' in document.createElement('span')) {
  alert("Drag support detected");
}
1 2 3 4 5 6 7 8 9