Archive for December, 2008

Facebook security

Tuesday, December 16th, 2008

I’m currently writing an application for facebook, most of this application will happen within an iframe, since I’m going to have to play with the layout etc. and I can’t figure out how to pass link to other pages facebook.
This all works well, until you try and transfer any data that someone may want to amend as links.
The normal way I’d do this is by passing values through cookies and POST. However, firstly this isn’t the most secure way of doing things, and secondly I won’t have the users password etc. I’ll just have to trust it’s facebook that calling the page, and not that it’s being called directly.

So I came up with a way of securing the information that is being transmitted by POST. That is to add a test variable to the POST string, and then check it on the other end. Of course someone could just recreate the hash of the variables and pass that, so for added security I’ve inserted a secret phrase and a date stamp to the hash.
This will work fine as long as the page isn’t opened before midnight and the link followed after (otherwise the date will be different and so will the hash) So, I’ve the checking routine checks not only the day, but the day before as well.

Calling.php

$user_id
$loc_id
$action

$passp = md5($user_id . $loc_id . $action . date(‘Y-m-d’) . “secret phase”);

echo “<a href=path.to/script.php?user=”.$user_id.”&loc=”. $loc_id .”$action=”.$action.”&check=”.passp” > link</a>”;

 

 

script.php

<?PHP
$passp = md5($_POST['$user_id'] . $_POST['$loc_id'] . $_POST['$action'] . date(‘Y-m-d’) . “secret phase”);

$nextDay = time() – (24 * 60 * 60);
$passp2 = md5($_POST['$user_id'] . $_POST['$loc_id'] . $_POST['$action'] . date(‘Y-m-d’, $nextDay) . “secret phase”);

if ($passp != $_POST['check']) {
 if ($passp2 != $_POST['check']) {
  echo “err… you’ve fiddled with the pass string”;
  exit();
  }
 }

PHP and CSS

Wednesday, December 3rd, 2008

PHP (PHP: Hypertext Preprocessor) can and has been used in lots of different ways to generate everything on a website, from HTML to Graphics, to PDF files. However one thing appears to have slipped under the radar of PHP developers and web site designers (maybe because both designers and developers guard there own domains very tightly) is using PHP to generate CSS files.

CSS (Cascading Style Sheets) are used to put a design around the content of a website, however there are a number of problems (mostly due to Microsoft) in their use, different browsers have different levels of adherence to CSS rules etc.

Traditionally designers have either used non-standard tags or other work-a-rounds to design different sheets for different browsers, this of course has increased the design time. However PHP has the functionality to be able to detect what browser is calling it, and so, be able to serve the correct CSS for that browser.

This still doesn’t significantly reduce the overhead in designing for multiple browsers on its own however there nothing to stop someone writing an in-house tool that takes a standard CSS file (written for browser X) and then generate a PHP script (or at least the input for a script) for multiple browsers. This of course will still need testing by human designers and most likely tweaking, but it should reduce the time needed to produce different versions of the same CSS file.

But there are also other tricks PHP can do to aid the design process. Since the whole of the layout process is governed by CSS it can be used to display different images dependent on, for example the time of the day, or month of the year.