A Case Study of Barterful.com

The following is a case study for the website Barterful.

Please swipe to the left to go forward or to the right to go backward.

A Case Study of Barterful.com

Barterful - Your Local Bartering Network

The Inspiration

In the second semester of the Humber College Web Development program we began learning PHP. Our project that semester was to build a website in PHP with at least 9 features/functionalities. We were allowed to choose groups of 3 - 4. My group consisted of myself, Michael MacPhearson, Ilana Beer, and myself.

A Case Study of Barterful.com

Step 1 - The Login Control

My group decided to use the Codeigniter Framework to speed up the development process. Codeigniter is a PHP framework, and it was my first time ever using the MVC (Model, View, Controller) style of programming. It took a bit of getting used to at the beginning, but we picked it up quite quickly.

Before we could start building the various features we chose for the site, we had to create a login control. This was one of the first PHP features I ever worked on, and I am proud of it.

The login feature needed to:

  • Grant access to existing members
  • Allow new users to sign-up
  • Validate that the username/email of a user was not already taken
  • Validate against malicious or duplicate form submission
  • Restrict access to non-authorized users

A Case Study of Barterful.com

The Sign-Up Function


The controller for the sign-up checked whether the user's was already logged in. This is done using the PHP userdata session information. I coded the login so that whenever a user successfully logs into the website, the fact that they are logged in is stored in the session data so they do not need to login for every page. If $logged_in is set to false, the page redirects the user to the login or sign-up form. If they are logged in when they try to access the login form, the user is redirected to the homepage.

The Code

	function signup()
		$logged_in = $this->session->userdata('logged_in');
		if(!isset($logged_in)|| $logged_in != true){
			$this->data['main_content'] = 'signup_form';
		$this->load->view('includes/template', $this->data);

A Case Study of Barterful.com

The Create Member Function

The Code

function create_member(){
	$this->form_validation->set_message('check_if_username_exists', "This Username is sadly already taken. Nice try though!.");
	$this->form_validation->set_message('check_if_email_exists', "Someone has already signed up with this email address. Our sincerest apologies!.");
	$this->form_validation->set_rules('email', 'Email Address', 'trim|required|valid_email|callback_check_if_email_exists');
	$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|callback_check_if_username_exists');
	$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
	$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'trim|required|matches[password]');
	if($this->form_validation->run() == FALSE)//didn't validate {
		if($query = $this->membership_model->create_member()){
			$this->data['account_created'] = 'Your account has been created. 

You may now login'; $this->index();} else{ $this->signup(); } } } function check_if_username_exists($requested_username) { //custom callback function $this->load->model('membership_model'); $username_available = $this->membership_model->check_if_username_exists($requested_username); if($username_available){ return TRUE;} else { return FALSE; } }

This controller is getting the form input from the "Sign-Up" form. It loads the form validation library that is build into CodeIgniter. It then sets validation error messages that the user will see if the input they select is not validated. If the input is validated, the data goes to the membership model, where the new user is stored in the MySql database.

The second function checks if the username that the user has selected is available. It does this by checking whether the username that was inputed already exists in the database table "users". If it does, the the function returns false and causes a validation error informing the user that the username is already taken.

A Case Study of Barterful.com

That's it!

Feel free to head over to Barterful.com and check out the site for yourself!