Php

Create a random password with PHP

Some websites require access control, and sometimes you may need to generate a password for a user. Here’s a simple function that can do just that.

The $base-variable contains the characters allowed in the password. The supplied string may be changed, but the selected charaters should exist on all keyboards (as far as I know). When calling the function, you can specify the lenght of the password you want. Simple, right?

function makePassword($desiredLenght = 8) {
    $password = '';
    $base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

    for($i=0;$i<$desiredLenght;$i++) {
        $password .= $base\[(rand(0, (strlen($base)-1)))\];
    }
    return $password;
}

Cracking the Cryptex with PHP

In the book “the Davinci Code” there was a fun little device called a cryptex.. A Cryptex has 6 dials with 6  letters on each, and only one combination producing a word will open it. The most straight forward way to crack it would be to try every combination one by one, but there’s a substantial number of combinations and we know only those which a valid words is a candidate.

Checking requirements for PHP Applications

A great strength in PHP is that it’s so accessible, that almost anyone can get access to a PHP site and often will download “applications” for their site such as discussion boards, photo galleries and others. While it may easy to download such applications, it often happens that the people trying to get things to work, doesn’t read the requirements section of the install.txt or readme.txt file, and thus never get the application running and doesn’t understand what the problem was and how to fix it. This is a brief guide with some tips on how to improve usability in this area.

Zend Framework - Ready or not?

We are a fairly large PHP shop at work running some of the largest Danish websites. In a fairly new project, it was suggested that we considered using the Zend Framework to fast track development and piggy back upon some of the components provided by the framework. We looked at it, and said no – at least for now. Since the Zend Framework website does an excellent sales pitch on why you should use it, here’s some of the arguments why you should restrain from using the framework.

To hide a secret in the open

Suppose you want to write a system, which requires a password to do something. Not a login system, but just a shared secret. Suppose also, that you need to show someone the source code, but you don’t want him or her, the secret password can you do that. Sure. Here’s a simple way to do it with PHP.

XML-RPC with PHP

I’ve been playing with XML-RPC – a remote procedure calling using HTTP as the transport and XML. If you’re interested in how to use XML-RPC in PHP, go to the lab page on XML-RPC with PHP.

Cracking the Cryptext with PHP

In the book the DaVinci code there’s a fun little device called a “Cryptex”. It a container for a secret message, and to open it, you need to align some dials to the correct position. In an quiz somewhere you were invited to crack such a cryptext consisting of 6 dials with 6 letters on each to find the correct combination, which would spell a word. To find the solution quickly, all you need is PHP.

Do you use PHP Constants?

Browsing in other people code can be an interesting experience. Sometimes you learn stuff, other times you just get scared of the things you see. One recent observation I seem to make a lot, is that handling “application configuration” is often handled less gracefully as a would have wished. The plain basic configuration handling in many PHP applications seems to be creating a php-file and declare all configuration values in this file – then have all other scripts in the application include this one config file – and sure it works.