看了《PHP敏捷开发框架CodeIgniter》第五章前半部分的内容,做了个登录小实验,文件如下:

控制器文件:start.php

登录视图:entrypage.php, 很简单,就是输入用户名和密码!

主页:更简单,就是一行字,"you are right"。

 

start.php:

<?php
class Start extends CI_Controller
{
 function __construct()
 {
  parent::__construct();
  $this->load->helper('url');
  $this->load->helper('form');
 }

 function index()
 {
 // $data['mytitle']="My site";
 // $data['base']=$this->config->item('base_url');
 // $data['css']=$this->config->item('css');
  $data['mytitle']="A website to monitor other websites";
  $data['text']="Please log in here!";

  $this->load->view('entrypage',$data);
 }

 function assessme()
 { 
  $this->load->library('session');
  $name=$_POST['username'];
  $password=$_POST['password'];
  if($name=='fred' && $password=='12345')
  {
   $newdata=array('status'=>'ok');
   $this->session->set_userdata($newdata);
   $ip=$this->session->userdata('ip_address');
   echo $ip;
   $this->mainpage();
  }
  else
  { 
   $this->index();
  ;}
 }

 function mainpage()
 {
  $this->load->view('mainpage');
 }
}
?>

 

entrypage.php:

<html>
<head>
<title><?=$mytitle?></title>
</head>
<body>
<?=$text ?>
<?=form_open('start/assessme');?>
<input type="text" name="username" value="username"/>
<input type="text" name="password" value="hi"/>
<input type="submit" value="submit" />
<input type="reset" value="reset"/>
</form>
</body>
</html>

 

mainpage.php:

<html>
<head>
<title></title>
</head>
<body>
you are right!
</body>
</html>

posted on 2012-01-12 14:22  vesa3.0  阅读(103)  评论(0编辑  收藏  举报