Pages

Showing posts with label CodeIgniter. Show all posts
Showing posts with label CodeIgniter. Show all posts

Saturday, March 19, 2011

CI - Date Parser

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * This class will provide parsing service for date time format:
 * month/date/year and hour:minute:second
 *
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : February 20, 2011
 */

class Parser {

    function parsee($data)
    {
        $this->datee = $data['date'];
        $this->timee = $data['time'];
       
        $this->date = array();
        foreach(explode('/',$this->datee) as $value){
            $this->date[] = $value;
        }
       
        $this->time = array();
        foreach(explode(':', $this->timee) as $value){
            $this->time[] = $value;
        }
       
    }
   
    function get_date(){
        return $this->date[1];
    }
   
    function get_month(){
        return $this->date[0];
    }
   
    function get_year(){
        return $this->date[2];
    }
   
    function get_hour(){
        return $this->time[0];
    }
   
    function get_minute(){
        return $this->time[1];
    }
   
    function get_second(){
        return $this->time[2];
    }
}

?>

Saturday, February 19, 2011

CodeIgniter App - Login Page

/**
 * Implementation of login page using CodeIgniter
 *
 * @author  : irfanudin ridho
 * @email   : irfan.ub@gmail.com
 * @version : 1.0
 * @date    : February 20, 2010
 */

<?php

class Blog extends CI_Controller{
   
    function index(){
        header("Location: blog/page");
    }
   
    // login form
    function page(){
        $this->load->view('blog/front');
    }
   
    // check the login validation  
    function check(){
        $username = $_POST['username'];
        $pass = $_POST['password'];
        // add more data
        $data = array(
            'username' => $username,
            'log_in' => TRUE,   // for the next checking
        );
        if(strcmp($username,"admin") == 0  && strcmp($pass,"bali") == 0){
            $this->load->library('session');
            $this->session->set_userdata($data);
            header("Location: hello");
        }else{
            header("Location: page");
        }
    }
   
    // authenticated page
    function hello(){
        $this->load->library('session');
        if(!$this->session->userdata('log_in')){
            header("Location: page");
        }
       
        echo "<h1>You are log in</h1>";
       
        echo "<a href=\"logout\">Go Logout</a>";
    }
   
    // logout page
    function logout(){
        $this->load->library('session');
        $this->session->unset_userdata('log_in');
        header("Location: page");
    }
}


blog/front.php - view files
<div id="login">
  <h1>Login</h1>
  <table>
   <form action="check" method="post">
    <tr><td>Username</td>
        <td>:</td>
        <td><input type="text" name="username"/></td></tr>
    <tr><td>Password</td>
        <td>:</td>
        <td><input type="password" name="password"/></td></tr>
    <tr><td colspan="3">
        <input type="submit" value="Log In"/></td></tr>
   </form>
  </table>
</div>

Friday, February 4, 2011

Blog Application Using CodeIgniter

This application use some file:
1. application/controllers/blog.php
2. application/views/blogview.php
3. application/views/form.php
4. application/views/view.php