Archive for the ‘PHP’ Category

I’m working on a Facebook app that needs to collect images from an external server. Normally I could use a function like copy to do this, but this requires allow_url_fopen to be on and a lot of providers like mine have this turned off to tighten server security.

Eventually I came across file_get_contents to do the job. Since this also needs allow_url_fopen to be on, my post on fetching page content with cURL came to mind.

This does the same thing without restrictions on privacy and is available on most current setups. Read More »

Collecting a random data set from your database can be useful for all kinds of data driven applications including analytics and “grey areas” in video game outcomes (battles, gambling, etc.).

Here I will discuss the use and methods of randomisation in PHP with data from a MySQL database. Read More »

For those that are unfamiliar with the Twitter API or are looking to quickly fetch tweets from a user’s profile, this class will help.

In PHP, all you do is include the class in your document and construct it with a Twitter username (with some options for extra tweaking). Read More »

The URL fragment anchor (or accelerator, ID link or jump point) can be used to relocate the visitor to a specific part of a page. This is done by giving an element an ID then linking to it with a hash symbol (# or number/pound sign) like so:

http://example.com/page.php#content

The “content” part of this URL however never gets passed to PHP since it is only used client-side. However, with a little bit of help from JavaScript we can do exactly that. Read More »

PHP sessions are great for dealing with log in systems, tracking user activity, and allowing them to save data as they move around your site, like a shopping cart. Writing up what you need to run it though can be a bit painful, so that’s what lead me onto creating a custom session handling class in PHP. Read More »

Back in September of last year, Jim Greer of Kongregate.com posted an article in the forums about a new badge data service served in JSON. This was great news for developers, we could finally grab data from our user accounts without having to do a web scrape on our user page.

However, this forum post seems to be the only official documentation on what is a very interesting data feed, so it is with this reason that I decided to create this beginner’s tutorial on how to use it. Read More »

The web has so many useful services now, many offering their own API that you can draw data from and create your own mashups with. Websites like Twitter, Facebook, Flickr, and Kongregate are just a few.

Their data output is most commonly formatted in RSS (for feed readers), and JSON (a lighter form than XML used a lot for AJAX). In this post I’ll show you how to use the cURL library to collect data from any public web page. Read More »

In the below examples I’ll use data from a fictional database table named “users”. We’re looking to return the 10 most recently added users with a date of birth later than January 1st 1970.
Read More »

At the point that your site becomes more complex, you look to ways of simplifying your page code to give yourself less headaches. Ultimately you’re looking for a way to separate that header that you’ve copy-pasted so many times to different static web pages, into a page that all your other pages can call, and will stay the same.

If like me you hadn’t heard about PHP until this point where you are looking to add in other scripts to your web pages, then now is a very good time to learn about PHP includes.

1
< ?php include( 'header.html' ); ?>

Read More »