Archive for February, 2007

PHP - Online Quiz Game

Tuesday, February 27th, 2007

This is a ready to go example. Basically, it enables you to create online quizzes and validate them, displaying number of guessed answers. Since it is written in object oriented manner, it is easy to extend its capabilities.

Example uses three DB tables and seven classes.

DB tables are:

quiz_quizzes
quiz_questions
quiz_answers

Relationship between quiz, question and answer is: quiz have one or more questions, and each question have one or more answers. Only one answer is correct. So, each quiz have unique QuizID. Each question have unique QuestionID and it is connected with quiz through its QuizID. Each answer have unique AnswerID and it is connected with question through its QuestionID.

(more…)

PHP - DB authentication system

Tuesday, February 27th, 2007

Here you have an example of a pretty complete and "ready to go" class for user authentication system. Although the class is user based, there are several methods not quite about users, but these are helpers for quick start.

DBConnect - connects to database;
DBDisconnect - disconnects from database
CreateSecurityUsersTable - creates table for storing usernames and passwords
GetUsers - creates an array with users info
Insert - creates new user.
Update - modifies user info
Delete - deletes user
ChangePassword - updating password is separated from Update
CheckLoginCredentials - check username and password
GetUserInfoByName - gets user info by provided name
GetUserInfoById - gets user info by provided user id

(more…)

PHP - Turing test

Tuesday, February 27th, 2007

Turing test is a small image with random text which user should enter in order to process his further requests. It is based on presumption that text on image could be recognized only by humans. This is the reason why you will find these images very distorted. Basically, web server will create image background, simple text and apply image distortion with mathematical function. This way, web server makes impossible to use OCR software to recognize text on the image.

(more…)

PHP - Image filters

Tuesday, February 27th, 2007

One of many advantages of PHP5 over PHP4 is ability to process images with various image filters.

According to PHP manual, you can
1. Convert image to negative
2. Convert image to grayscale
3. Set the brightness of an image
4. Set the contrast of an image
5. Colorize image. This filter will change color saturations in your image.
6. Edge detection. This filter will highlight the edges of objects on image
7. Emboss. Filter will create a relief of image.
8. Blur. Blurs the image. This filter have two variations, Gausian blur and Selective blur.
9. Mean removal. This filter will make your image looks like a sketch.
10. Smooth. Filter will make object edges transitions smoother.

(more…)

PHP - Protected download

Thursday, February 22nd, 2007

In this example, we are protecting a file from an unauthenticated download.
The script will ask for username and password, and if it is OK, it will send a file. Notice, that we do not give file URL. We are sending file through PHP script, so the real location of the file stays secret for the outside world. The downside is that a user cannot continue an interrupted download.
Depending on the server configuration, you may not have sufficient permissions to use mime_content_type (it is disabled by default). If this is a situation, just hardcode your MIME type.

(more…)

PHP - Sessions

Thursday, February 22nd, 2007

Sessions allow us to save user "state" between subsequent visits to the page. Sessions and cookies are similar mechanisms. Both allow us to save data, which will be available to us at a later visit. Main difference is that session data is stored on a web server, while cookies resides on client machines. Because of this, sessions are capable of handling much more data than cookies.

Sessions work in the following way: when a user visits your web page, he stars a session and gets assigned a unique ID. This ID is called Session ID (SID). SID is sent to a user using a cookie.

(more…)

PHP - Compressing a file

Thursday, February 22nd, 2007

This example shows how to create gz archive.

<?
  $fp = fopen("/file.dat", "r" );
  $content = fread ($fp, filesize("/file.dat"));
  fclose($fp);
  $fp = gzopen("/file.gz", "w9" );
  gzwrite($fp, $content);
  gzclose($fp);
?>

PHP - Downloading a file

Thursday, February 22nd, 2007

This example will show you how to download a file from a remote location.
First we will open a connection to remote host. We will use fopen function to do that. You could also use functions from sockets module if you want more power to control socket behavior. When you open a connection with fopen, you can read and write to that connection just like from/to a file. fopen is good because it is easy to use.

(more…)

PHP - Mailing list

Friday, February 16th, 2007

The following is an example of a class which can be used to handle a mailing list.
Everything is bundled into one class, for your quick start.

Commands are sent through GET requests, like this:

emaillist.php?command

Available commands are:

create - creates db table for storing addresses
list - lists all addresses in database
unsubscribe - displays unsubscribe form
write - displays form for writing messages

There are command which can be sent through POST request, and they are used through available forms.

(more…)

PHP - Sending messages with attachements

Friday, February 16th, 2007

This one is little tricky. We need to form the message in a special way.
Our message will be divided in at least two parts, one for the message and one for the attachment.
This is a so called MULTIPART message.
These two parts need to be separated, so we need a BOUNDARY between them. We will form the message by reading the content of the attachment and then converting it so that it can be transfered by email.
In the following example, we will send an HTML message with an attachment.
(more…)

PHP - Sending an HTML Message

Friday, February 16th, 2007

Sending an HTML message is very similar to sending a plain text message.
The important difference is the message header.

<?php
$Recepient = "somebody@somewhere";
$MsgSubject = "Message subject";
// You must set sender through message header
$MsgHeader = "From: Sender name<sender@server>\n";
// You need these two lines
$MsgHeader .= "MIME-Version: 1.0\n";
$MsgHeader .= "Content-type: text/html; charset=us-ascii\n";
// Message body is HTML
$MsgBody = "
<html>
<head>
  <title>HTML message</title>
</head>
<body>
  <h2>Congratulation!</h2>
  <p>You have just learned how to send a HTML message</p>
</body>
</html>"
;
mail($Recepient, $MsgSubject, $MsgBody, $MsgHeader);
?>

PHP - Inside a class

Friday, February 16th, 2007

Classes consist of variables and functions. These elements have a scope, they can be visible or not outside of a class. Scope of class members can be public, protected or private.

When member is declared public, it is visible outside of a class and can be used anywhere where object of that class can be used.

When declared protected, it is visible only inside a class and its subclasses.

When declared private, it is visible only inside a class which declares that member.

We declare class member as public, protected or private by putting one of the keywords public, protected or private in front of member declaration. If we omit scope identifier, member is considered public.
(more…)

PHP - Constructor and Destructor

Friday, February 16th, 2007

Every class has two special functions, constructor and destructor. Even if you do not explicitly declare and define them, they exist (they are empty).

Constructor is a function which is called right after you create a new object. This makes constructor suitable for any object initialization you need.

Destructor is a function which is called right after you release an object. Releasing object means that you do not need it or use it anymore. This makes destructor suitable for any final actions you want to perform.

Here we come across first difference between object oriented code in PHP4 and PHP5.
(more…)

Powerset jobs

Thursday, February 15th, 2007

Powerset LogoPowerset is a Silicon Valley company building a transformative consumer search engine based on natural language processing.

Powerset offers the opportunity to work in an open, challenging and fun environment with some of the most brilliant people in the search industry on technology that is going to fundamentally open up a whole new area of engineering for search engineers.

To learn more about Powerset visit Powerset.com
For a full list of jobs click here

Announcing Careers Section

Thursday, February 15th, 2007

To show our continuing support for our students, we have decided to create the career section. We will post jobs and interesting project which would allow our students to apply their skills right away.
Whether you are looking for a new career or just looking to invest your free time contributing to revolutionary Web 2.0 projects, we will try to help you find the opportunity.

If you represent a company, organization or a project that is looking to grow, please send us your career opportunities and we will post them here.