Alex Briffett Life is just a state of mind

17Feb/100

Internet Explorer Clears PHP Session Cookies

I set a session cookie in a PHP script accessed via an iframe in a Google Site as a gadget. The PHP script did a check on the user and if ok, set the session cookie so that they could access secure information on another system on the same domain as the first PHP script. Once the cookie was set, I used a redirect to let the user access the secure information...

<?php

if ($user == 'ok')

{

session_start();

$_SESSION['allowed'] = 1;

header("Location: securepage.php");

}

?>

This worked fine in Firefox and Chrome but not in Internet Explorer 7. Having debugged the code, I realised that the $_SESSION['allowed'] = 1 was not making it to the secure information PHP script. Internet Explorer was deleting or not receiving the PHP SESSION information.

This appears to be a security measure in Internet Explorer 6, 7 and potentially 8. In any case, the fix is to do the following on the first PHP script where you start the session.

<?php

if ($user == 'ok')

{

session_start();

header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');

$_SESSION['allowed'] = 1;

header("Location: securepage.php");

}

?>

This extra P3P header tells Internet Explorer to accept the cookies from the first PHP script as it links or redirects to the securepage.php. I am not sure why IE would interpret doing this as a security threat but it could be to do with doing a header("Location... from within an iframe. Security level in Internet Explorer was set to medium-high.

Filed under: Blogs, Web Code No Comments
14Jan/100

Simple PHP Function to Maintain Drop-Down State

This PHP function is a quick, simple way to maintain the state of select / drop downs when the form input is invalid.

/**
* Function to draw drop down boxes and allow the state to be maintained
* if the form has an error
*
* @param array $vals - select box values
* @param array $text - select box show values
* @param string $search - the name/id of the select box to be searched for
*/
function dropDown( $vals, $text, $search )
{
for ($i=0; $i < count($vals); $i++)
{
if ($search == trim($vals[$i]))
{
$selected = "selected=\"selected\"";
}
else
{
$selected = "";
}
$result .= "$text[$i]\n";
}
return ($result);
}
?>

Filed under: Web Code No Comments
14Jan/100

PHP 5+ and MySQL 4.0 Could not connect

Hopefully you should never encounter this problem but I recently needed to do an insert into a MySQL 4.0 table from a remote installation of PHP 5.  I could connect from the PHP5 server to the MySQL 4.0 server via the command line, so assumed this would work find using PHP5.

I got the following error: Could not connect: Connecting to 3.22, 3.23 & 4.0 servers is not supported

Basically, later versions of PHP use a password encryption algorithm which means they are incompatible with MySQL 4.0 but not MySQL 4.1+.

Since the command line connection worked, the solution was to create a shell script on the PHP5 server which looked similar to the following:

#!/bin/sh

/usr/bin/mysql -u USERNAME -pPASSWORD DBNAME -h HOST<<STOP
insert into table (name, email) values ('$1','$2')
\g
STOP
exit

You will need to swap the capitalized variables for your own USERNAME, PASSWORD, DBNAME and HOST.

I called the shell script doinsert.sh and chmodded it 755 to make it executable.  Then, in my PHP script I used:

<?php

$r = shell_exec('./doinsert.sh ' . $name . " " . $email);

?>

...which executes the shell script and runs the insert statement I was aiming for. If you want to run a select statement instead of my insert example, then anything returned by the shell script should be available in $r.

18Oct/094

What Is This?

What could this close-up photograph be of?  It looks a bit like shark's teeth at first glance...any other guesses? Leave a comment with your guesses and no cheating.

Click the photo to see what it really is.

Guess what this is?  Sharks' teeth perhaps?

Guess what this is? Sharks' teeth perhaps?

17Oct/091

Unnecessary Umlauts

The umlaut is a diacritic mark used to represent a sound shift in spoken language [see: wikipedia:umlaut] It is usually represented by a pair of dots above the affected letter.  In German you often see it used in the the following characters Ö, Ä, Ë.  Words like schön (nice) in German are sometimes written with an extra 'e' as in 'schoen' to represent the umlaut where the umlauted character is not available. It is perhaps because of this German / European use of the umlaut that is has achieved a cool status in design, music and social networking.

The umlaut is now appearing, unnecessarily, in many modern trademarks and names.  None of these words actually require an umlaut to represent any vocal sound shift, rather it is purely an aid to design.  Blogger and designer ultamagnus79 also noticed this and has used the umlaut device to great effect in his visual experiments.  I took the 'graffiti' picture below in Horsham park and interestingly this example includes an umlaut over a letter 'g' with no pretence at following any rules of grammar, it is purely a fashionable adornment to the 'nothing ever matters' statement.

So, if you are a graphic designer, a member of a band looking for a name or the developer of a Web 2 style app or site, please consider the humble umlaut.  It could add a 'street' element with yet an air of European sophistication to your product.  Also, you do not have to learn German to use it properly; the old rules no longer apply.

Graffiti featuring umlauts

Graffiti featuring umlauts

Bunker Bar logo featuring umlaut over the 'u'

Bunker Bar logo featuring umlaut over the 'u'

Snatptu Logo with smiley umlaut

Snatptu Logo with smiley umlaut

Motorhead logo with umlaut over the 'o'

Motorhead logo with umlaut over the 'o'

9Sep/090

i-nigma barcode

i-nigma barcode

i-nigma barcode

Point your mobile phone's browser to http://www.i-nigma.mobi and download the barcode reader.  Point your phone at this barcode and get a link or message.

Ok, so it is just a quirky bit of fun at the moment but you can see the benefits.  I imagine band fly posters with barcodes instead of web links.  It would save all the kids living in mobile world the inconvenience of using predictive text with weird band names or attempting to type in the www address for gig lists etc.

I expect, if the idea catches on, we will see it on adverts for major brands soon.

10Jun/090

Book Review: The Three Little Wolves and the Big Bad Pig: ISBN: 0-434-96050-0

Three Little Wolves

This is more of a recommendation rather than a review. Eugene Trivizas and Helen Oxenbury(illustrations) have collaborated on a true comedy masterpiece. The book is basically the Three Little Pigs turned on its head with hysterical comic effect. Despite possibly aimed more at putting a smile on adult faces, the topsy-turvy nature of the story, compared to the original, should not be lost on children as young as 4 or 5.

Although the violence of the story is updated, with mentions of dynamite and 'the pig went and fetched his pneumatic drill and smashed the house down', do not let this put your off. There is an unexpectedly happy ending. The Penguin version is actually far more violent with 2 pigs being eaten by the wolf and the wolf himself is boiled to death in a cauldron.

7Jun/090

First Decent Egg From Ex-Battery Hen

Ex-battery hen egg (left) compared with shop bough free-range egg.

Ex-battery hen egg (left) compared with shop bought free-range egg.

Our ex-battery hens have laid us a decent egg or two after just a few days in their new coop.  This photo shows a camparison between our hen's egg and a shop-bought free-range one.  Maybe after some more time, grit(crushed oyster shells), vitamins, greens and exercise from our garden, our chucks might produce a darker coloured egg.

Earlier attempts at egg laying produced eggs with very thin shells or even one with no shell at all.

12May/098

Chicken Coop

I bought a chicken coop with a view to keeping 3 chickens and we adopted three ex-battery hens. The manufacturers of the coop suggested it was big

Building fox-proof base for chicken coup

Building fox-proof base for chicken coup

enough for up to 4. I considered this a little mean, so decided to extend their coop by building a chicken run. I fox-proofed the coop by digging a hole about a foot deep underneath it and placed a wooden frame underlaid with chicken wire and placed the coop back on top.

A hen enjoying new chicken run

A hen enjoying new chicken run

I did the same for the chicken run itself and used 2 by 2 wood which I coated in wood preserver. The wood was tanelised but reckoned that every little helps. The run itself required 5 frames of timber covered in chicken wire and I screwed this together over the top of the sunken frame.

It required about £40 worth of timber, £25 worth of chicken wire (just over 20 metres) and around 200 screws. I suppose nails would have done just as well.

Custom built chicken run

Custom built chicken run

18Jan/090

Herbie? – What Is This Answer

Herbie is a bearded dragon I met in Brighton.  He belongs to some friend of mine and spends most of his days lazing under a hot lamp, climbing curtains or eating meal-worms and crickets.  What a handsome chap.  If you look at the photograph and turn your head to the left, his ear hole appears to be a left eye, whilst a flap of skin appears to be a mouth.  I wonder if he uses this device to trick insects into running away but into the path of his lightning-fast tongue or maybe it serves to frighten possible predators?

Herbie - a bearded dragon from Brighton

Herbie - a bearded dragon from Brighton