logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Luke America

Website

Bio:

I've been programming PHP and WordPress for several years. View my website, http://wpCodeSnippets.info, for some examples.

Answers Given: 18 (see them all)
Contests Won: 7
Prize Money Earned: $70
Questions asked: 0
Questions refunded: 0 (see all?)
Is a top asker (has the power to vote on anything):
Subscribes to all the discourse posted to the site?: No
Country: USA
City: Myrtle Beach
Netvotes this month (upvotes minus downvotes): 0
Netvotes of all time (upvotes minus downvotes): 0
Joined the site: April 19, 2011





Luke America's upvoted answers:






This member has no downvoted answers






Answers given to these questions:

See more?






Luke America has not voted on any questions






Luke America has not asked any questions






This member has not made any recommendations. If you are one of the top experts, please offer one now!






Luke America's discourse:

Written in response to Twitter feed plugin displays 1 feed, would like 10 per account:

Was my answer not acceptable to the Asker?

link

Written in response to Show tweet count as text for posts :

This "forbidden" error is likely encountered because you are not caching your data. Every time you pull the data in this fashion, their site gets a hit from you. Many services have these safeguards in place to prevent denial of service attacks.

You could cache the data in a file on your server or in a WP "transient" database table.

Or, you could use cURL with its built-in page retrieval cache to reduce the probability of setting off flags. With all of these solutions though, you will not get the very lastest data ... but mildly time-delayed.

I was just about to submit my solution when Baki Goxhaj replied. I didn't want to counter his incredibly fast response, but I knew there was a high probability you'd eventually start getting these sporadic 403's.

Try using this function instead of file_get_contents(). Just put it in your theme's functions.php file and call it instead of file_get_contents(). Once you're flag is cleared with their service, it should work in perpetuity. But, using a database transient is a better solution.


function curl_get_contents($url, $fresh_connect=false)
{
$result = false;
$url = str_replace(' ', '%20', $url);
$handle = curl_init($url);

if (is_resource($handle) === true)
{
curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_FRESH_CONNECT, $fresh_connect);

$result = curl_exec($handle);
curl_close($handle);
}

return $result;
}


link

See more?






Luke America has not had any questions refunded






Luke America has not posted any suggestions for appropriate prize amounts for questions.