Your profile page is fetched using PHP and the links and pictures scraped out of the html code from Instructables. These are then rearranged to look like the standard Instructables layout, your visitors clicking on them will take them straight to your Instructable.
All images are "hot linked", so there's no impact on your web server storage or bandwidth. All of this is done with the kind permission of Eric.
A list of some of the sites that have successfully installed this so far:
A full list of users that have used it successfully will be added to the last step and updated when I learn of new uptakes.
Many thanks to gmjhowe for helping me write the HTML and CSS used to make the results the PHP finds look pretty and for taking great photos for this Ible.
I have previously fetched web pages with Perl; this is my first attempt with PHP. A list of resources in the last step shows the websites that I used to learn how to do this, all of these were invaluable.
Step 1: How it works
The code works in these steps:
- The PHP uses the $_GET function to get the information stored in the offset and sort variable in the URL, just like it does on Instructables.
- A URL for the Instructables page to be fetched is constructed from the variables $sort, $offset and $username. Depending on the user to be displayed, the sort method to be used and the number to offset by, it may look something like this: http://www.instructables.com/member/Jayefuu/?show=INSTRUCTABLES&sort=NAME&limit=15&offset=15
- The Instructables page constructed in step 2 is fetching using the PHP function curl() and stored in the variable $html.
- A list of links replicate the "sort by" function included in Instructables. Clicking these takes users to the same page, but changes the "sort=NAME" part of the URL. The current sort method isn't a link, it's in bold.
- A regular expression is used to determine whether there is a next or previous button on the page fetched. These are then printed to the screen.
- One massive regular expression is used to find the 15 Instructables on the page. Their titles, URLS, title image thumbnails and featured status are stored in an array.
- A piece of code iterates through the array and prints html to the screen. This is what is displayed by your browser, not the PHP, which is executed on the server.