PHP


I have been playing with Flex a bit, to write an Flash application for my masters degree (I find the flex environment much better for programming than flash), and like most people working with flash I have come up against the cross domain issue (where the player won’t pull data from a domain which doesn’t have a cross domain policy allowing them to do so). This is a problem for the application I am working with, because I want to pull RSS feeds.

The obvious answer, a php proxy. In a way that makes it sound grander than it is because all it really is is a script to pull data from a remote source to get around the cross domain issue.

here is the script (simplified):

<?php
	header("Content-Type: application/xml; charset=UTF-8");
	$url = $_GET['url'];
	readfile($url);
?>

Now the code pulls back the feed as expected, but prepends this:

67c0

immediately before the content. Where does that come from, any ideas? Wherever it comes from it obviously means the feed won’t parse!

In the end, I used curl like this (simplified):

<?php
	header("Content-Type: application/xml; charset=UTF-8");

	// note that this will not follow redirects

	$url = $_GET['url'];

	// create a new curl resource
	$ch = curl_init();

	// set URL and other appropriate options
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HEADER, 0);

	// grab URL and pass it to the browser
	curl_exec($ch);

	// close curl resource, and free up system resources
	curl_close($ch);
?>

Technorati Tags:
, , , ,

I’ve been using PHP for years, but had never used the quick if construct:


$var = (conditional) ? ‘true’ : ‘false’;

?>

Beautifully simple; but not in any of the books I used to learn PHP!

Technorati Tags:
, ,

I wanted an alternative to having phpMyAdmin installed on my server as I couldn’t help but be a little concerned about having a web application that has access to all my databases. The alternative?

I present here for your reading pleasure 2 alternatives, based around 1 simple principle:- ssh tunneling.

  1. Set up an SSH tunnel in terminal:

    ssh -L 3396:127.0.0.1:3306 username@WebServerIP

    or use ‘SSH Tunnel Manager‘ or ‘Almost VPN‘ or the like.

    I’m using port 3396 on the local machine just ’cause it’s easy to remember.

  2. Now set up either phpMyAdmin running on your local version of apache (Personal Web Sharing under Sharing Prefs Pane) with php (get Marc Liyanage’s PHP Apache Module if you don’t already have php installed), making sure that you put 127.0.0.1 as the MySQL host, and 3396 as the MySQL port in the config.inc.php file.

    Alternatively, despite being a long term phpMyAdmin user, I have switched to the combination of the MySQL Administrator application and CocoaMySQL-SBG for full GUI database administration loveliness. Again, with both apps, use 127.0.0.1 as the host, and 3396 as the port.

    NB: because the tunnel is essentially making the database access happen on the server itself, the user details you use can be limited to access by localhost only.

Easy. All you have to remember is to start the tunnel before you use the administration tools.

All Clear? SteamSHIFT out.

Technorati Tags:
, , , , , , , ,

After a few people have had problems with the old widget, where the version of the Category Tagging plugin had been updated, thus breaking the widget, and with the debugging help of Nicholas Feasey, now available is a new version. This version has imported the plugin code (Category Tagging Plugin), so I can only claim to have connected all the dots as it were. The upshot of this is that the widget can now operate independently of the plugin; hopefully this will make it easier.

Download Category Cloud Widget Version 1.2

Technorati Tags:
, , ,

A little while ago I moved my blog from Blojsom to Wordpress - for anyone who might find it useful, here is the php script I used to automate most of that process. I’ll try and post a new, tidier version down the line.

Download my Blojsom to Wordpress Importer.

Just put it in the web folder of your site, fill in the details at the top of the file and visit the page with a web browser. It’s clunky but it worked for me! Usual caveats - no guarantees, or warranty - if anything goes wrong, it’s not my responsibility! NB: it currently requires the PEAR DB library.

SteamSHIFT out.

Technorati Tags:
, , , ,

A simple update to the widget I made for the Category Tagging plugin: you now specify the parameters for the tag cloud in the widget control. Download the widget.

Technorati Tags:
, , ,

Real quick post for really quickly knocked up widget. So I decided to stop using categories as categories and use them as tags; much more straightforward. I’m using the Category Tagging plugin which is really neat and works really well. However, I wanted to use it a widget. So here is my first widget: all it does is grab the cloud from the Category Tagging plugin and display it. It needs all the Category Tagging plugin options connecting to the widget control interface rather than being hard coded; but it works! Here is the CSS I used (I put it at the bottom of the stylesheet)

CSS:
  1. #sidebar ul .tagcloud {
  2.     padding: 0;
  3.     margin: 0;
  4. }
  5.  
  6. #sidebar ul .tagcloud li {
  7.     display: inline;
  8.     list-style: none;
  9.     background-image: none;
  10.     padding: 0;
  11.     margin: 0;
  12. }
  13.  
  14. #sidebar ul .tagcloud li a {
  15.     background-image: none;
  16.     padding: 0;
  17.     margin: 0;
  18. }

Technorati Tags:
, , ,

When I am not mucking about with Quartz Composer and interesting electronic bits and bobs, I work as a web developer. I came across a problem recently where some of the work I was doing on one site affected another on the same server. As I wasn’t watching the log files of the other server, I was unaware of the problem - not good!

PHP has functions built in for dealing with errors, but these don’t extend to Fatal Errors and Parse Errors. What to do? The Apache error log mechanism where the PHP errors end up can cope with being given a program instead of a file. So some dubious shell scripting later, I now have a program that appends the result to the correct error file as usual, but also checks to see if the error contains either of the strings ‘PHP Parse’ or ‘PHP Fatal’ and if so, emails the error to me.

Problem solved - instant notification (contact me if you want the script)!

SteamSHIFT out.

Technorati Tags:
, , , ,