Application Access Levels with PHP

February 28th, 2009

Hello all

This week we got a job in to write an intranet site for a large Insurance company in the UK.

It had 60 or so applications that needed writing with access to each being given on a per user basis.

So for example user “A” could see applications 1 and 3, and user B could only use application 2.

So how do you do this easily?

We started off having a link table, it had User ‘A’ mapped to application 1 and so on. Which is ok but they have 5000+ staff and 60 applications so that would be a table with 300,000 rows in it, which in its self in MySql is nothing really, it just seemed excessive.

What we came up with is a bitwise solution so each application had a bit assigned to it. So if you remember your binary “0 1 2 4” etc. Each application was assigned a binary number, so application 1 was “1” in binary, application 2 was “10” ,application 3 was “100” and so on

So if a user as an access level of 7, that would translate in to a binary number of 111 so they could access application 1, 2 and 3. If a user had an access level of 4 for example they could only access application 3.

Binary (Base 2) Application
0 Superuser
1 Application 1
2 Application 2
4 Application 3
8 Application 4

We will post the class over the next few weeks if any body else wants to use it.

Happy coding

Oracle Databases on Windows

October 11th, 2008

We have done a lot of Database work using PHP applications and nine times out of  ten we end up using an MS SQL server backend instead of the standard mySQL backend. MS SQL has so many plus points compared with mySQL, the biggest being speed, recovery, backup and database management.

We have, however, been testing with Oracle in the past month or so. As most of us here come from a DBA background and are used to using  Oracle in large Banking and Financial systems, we would choose Oracle at the drop a  hat if the  TCO  was in the right ball park. With the release of Oracle on windows, it has now come into the same ball park as MS SQL, and having  access to Oracles RAC would be a great advantage as it seems to be even better than MS SQL 2005 mirroring.

We will let you know how our testing gets on and we will hopefully have some benchmarks between MS SQL and Oracle 11g to show how they get on with PHP.

Is a date in a given range using PHP

July 21st, 2008

To find if a date is in a given data range, the quikest way is to turn all dates to Epoch dates and then do a compare.

So to test if 31/12/2007 is in a date range of 10-10-2000 and 10-10-2008 do the following

$From=”31-12-2007″;
$To=”10-10-2008″;
$Checkdate=”01-01-2008″;

if (
( mktime(0,0,0, date(”m”,strtotime($From)),date(”d”,strtotime($From)),date(”Y”,strtotime($From)))
<=
mktime(0,0,0,date(”m”,strtotime($Checkdate)),date(”d”,strtotime($Checkdate)),date(”Y”,strtotime($Checkdate))) )

&&

(mktime(0,0,0,date(”m”,strtotime($To)),date(”d”,strtotime($To)),date(”Y”,strtotime($To)))
>=
mktime(0,0,0,date(”m”,strtotime($Checkdate)),date(”d”,strtotime($Checkdate)),date(”Y”,strtotime($Checkdate))) ) ) {

print “In Date Range”;

} else {

print “Not in Range”;
}

Hope this helps.

Mamma Mia the Movie

July 16th, 2008

What can I say, I thoroughly enjoyed the film in its own right as a funny film with actors that keep busting in to song, and to be fair I recognised most of the songs.

The only painful part was Pierce singing, probably because he reminded me of my brother-in-law who sings in pubs in southern Ireland.

Apart from that, it was a very easy film to watch. So it gets my vote especially if you want to earn some brownie points.

According to MSN this week it has made over £7.5million pounds in the first week at the box offices so it sounds like a few people have be to see it already.

Building a database for your website Part 1

July 6th, 2008

So you want a database for your website, so where do you start?

When I started to write this, I thought just a few lines with all the big bullet points in would do but after hitting 4 pages in ms word , I decided to split it down so here is Part1

Database Design for the Internet 101 Part1

Firstly you need to decide what information you will need? Sounds obvious but you don’t want to go down the spaghetti programming methodology if you can help it as it will cause you problems later on. So the best place to start is a blank A4 piece of paper and create an ERD.

An ERD is a graphical representation of the Database, where you can see the Relationships between the data you want to store. Drawing it out has a lot of advantages as you can chop and change it about very easily at the start before you build the database.

In these diagrams you can use the infinity sign to indicate a 1 to many relationship and lines to link fields. So as you can see from the example diagram above for each Registration you can have multiple payments.

In the Payments table there is a field called RegistrationID which links to the RegistratioinID in the Registration table. And then in the Payments table there is a Payment type which links to the Payments type table.

So why layout the data like this? Its all about data integrity, take the above example, if every time a payment was made the user had to enter a card type there could be all sorts of variations and typos in the table for example “VISA”, “Visa”,” VISA”,”Visa “, “Bisa” so by adding a PaymentsType table, this gives them the ability to select from a know and verified list. Going through this process is database normalization, for a database to work well you want to get to what is called the third nominal form where no data is replicated.

There ends Part 1, Part to will cover more on data relationships and normalization.

Do I need to do SEO Search Engine Optimisation

July 2nd, 2008

It’s not a resounding “YES” as you might think.

If your business is on the brink of closing then there are better ways to get exposure and possible sales over the Internet other than SEO.

These include PPC and traditional marketing activities. Another reason is that you are planning to totally change your website in the very near future, in this case its better to make sure your new website is written correctly in the first place and that will give you a good base to work from.

Do I need an external company to do my SEO?

99.9% of the techniques can be found by trawling the Internet and by using some common sense.

SEO is not a quick “switch it on” solution. It takes ongoing time, effort and energy.

So it’s a standard business decision whether you can allocate the time to do it your self or where it’s more cost effective to get an external company to do it.

You see companies offering SEO from £100 one off fee; basically these need to be avoided like the plague as just doing a couple of hours work and then never revisiting the site will NOT work.

SEO will take time it’s not an over night fix and should be considered an ongoing project.

We are currently writing a series of documents on DIY Optimisation for those people that want to do it for them selves and these should be available in August 2008 so please pop back to read them.

How to make php code run in .html files

July 2nd, 2008

This is a fairly simple one. If your website is hosted on an Apache Web Server then you can just edit or add a file called .htaccess. Inside this file you will need to add a line

addType application/x-httpd-php .php .phtml .html

This tells the web server that files ending in .php .phtml and .html are to be checked for PHP code.

By using the .htaccess method you will not need to restart apache to pick up the changes as apache looks for the .htaccess file each time a page is requested.

If you have to create an .htaccess file you will need to make sure the file permissions on it are 644. Or if setting via an ftp package Owner = Read/Write and the Group and Other will be set to READ only.

You should now be able to put sections anywhere in your html pages.

So why would you want to do this? There are a number of reasons, some of which are

  • Standard Header and Footers
  • Standard Menus
  • Displaying Date & Time
  • Displaying information from a database

Get Working Days between 2 dates with PHP

June 30th, 2008

We needed to work out the working days between two dates for a small calendar application we had to write. After looking round the net for a few minuets we decided to write a quick function for ourself.

It takes 3 inputs. A From Date (Epoch) , a To Date (Epoch) and an array with Bank Holiday dates in it. By the time it has finished it has a variable $WorkingDays with the number of working days in the give range.

The main logic goes like this

while ( $StartTime <= $EndTime ) {
if (
date(”D”,$StartTime) == “Sat” ||
date(”D”,$StartTime) == “Sun” ||
array_key_exists(date(”Ymd”,$StartTime),$BankHolidays) ) {

$IgnorDays++;

} else {
$WorkingDays++;

}

$StartTime=$StartTime+86400;
}

What is Optimised Website Design

June 29th, 2008

Optimised Website Design so what is it?

Optimised Website Design is the process of making a website very easy for search engines to read and catalogue, and yet still making the site easy to use for its intended audience.

The main thing to remember is “Then Content is King”, if your site layout is great but you have little or no relevant content to the search terms your are trying to achieve it will not work.

12 Simple Rules to Follow for an Optimised Website

  1. Make sure all the pages are W3C compliant
  2. Make content on each page relate to the page
  3. Make Page name relevant
  4. Use the alt tag on every image
  5. Use the title tag on every href
  6. Use the dfn tag for acronyms
  7. Make sure you can get back to the page you came from
  8. Have appropriate meta tags on the page for the content
  9. Make sure that there are no broken links
  10. Use h1’s and h2’s
  11. Regularly add content. A page a week is good
  12. Keep going and don’t give up, you will get there

If you want more information or Free advice please feel free to contact me at Wrekin Web Design Tony

Why we like PHP

June 28th, 2008

For many years we have used many different programming  languages  including COBOL , Rexx ,  VB , Perl .
About 6 years ago we decided to try PHP in place  of PERL for our CGI scripts and was amazed at the speed difference between the 2.

Even now we find new functions each day last one we found was the ” array_key_exists ” a very useful little function that saves checking all keys in an array.
We used it in a small calendar application for checking if a date was a bank holiday
More to Follow….