php框架ci,php框架cms ruhexuexi

http://www.itjxue.com  2023-01-20 00:50  来源:未知  点击次数: 

Php的ci框架怎么做后台管理系统?一些按钮怎么写出来的!?

ci框架只提供一系列后端代码的扩展以及管理,你想要写个后台管理系统需要自己写,不像drupal可以直接生成代码。

php ci框架验证码实例分析

php代码

复制代码 代码如下: ?php class Captcha_code { var $width= ; var $num= ; var $height= ; var $name= randcode ; public function __construct($conf="") { if($conf!="") { foreach($conf as $key=$value) { $this $key=$value; } } } function show() { Header("Content type: image/gif"); /* * 初始化 */ $border = ; //是否要边框 要: 不要 $how = $this num; //验证码位数 $w = $this width; //图片宽度 $h = $this height; //图片高度 $fontsize = ; //字体大小 $alpha = "abcdefghijkmnopqrstuvwxyz"; //验证码内容 :字母 $number = " "; //验证码内容 :数字 $randcode = ""; //验证码字符串初始化 srand((double)microtime()* ); //初始化随机数种子 $im = ImageCreate($w $h); //创建验证图片 /* * 绘制基本框架 */ $bgcolor = ImageColorAllocate($im ); //设置背景颜色 ImageFill($im $bgcolor); //填充背景色 if($border) { $black = ImageColorAllocate($im ); //设置边框颜色 ImageRectangle($im $w $h $black);//绘制边框 } /* * 逐位产生随机字符 */ for($i= ; $i$how; $i++) { $alpha_or_number = mt_rand( ); //字母还是数字 $str = $alpha_or_number ? $alpha : $number; $which = mt_rand( strlen($str) ); //取哪个字符 $code = substr($str $which ); //取字符 $j = !$i ? : $j+ ; //绘字符位置 $color = ImageColorAllocate($im mt_rand( ) mt_rand( ) mt_rand( )); //字符随即颜色 ImageChar($im $fontsize $j $code $color ); //绘字符 $randcode = $code; //逐位加入验证码字符串 } /* * 添加干扰 */ for($i= ; $i ; $i++)//绘背景干扰线 { $color = ImageColorAllocate($im mt_rand( ) mt_rand( ) mt_rand( )); //干扰线颜色 ImageArc($im mt_rand( $w) mt_rand( $h) mt_rand( ) mt_rand( ) $color ); //干扰线 } for($i= ; $i$how* ; $i++)//绘背景干扰点 { $color = ImageColorAllocate($im mt_rand( ) mt_rand( ) mt_rand( )); //干扰点颜色 ImageSetPixel($im mt_rand( $w) mt_rand( $h) $color ); //干扰点 } //把验证码字符串写入session //$this session set_userdata(array($this name=$randcode)); $_SESSION[$this name]=$randcode; /*绘图结束*/ Imagegif($im); ImageDestroy($im); /*绘图结束*/ } } ?

调用php代码

复制代码 代码如下: function verify_image() { $conf[ name ] = verify_code ; //作为配置参数 $this load library( lib_captcha $conf); $this lib_captcha show(); $yzm_session = $this session userdata( verify_code ); echo $yzm_session; }

代码

复制代码 代码如下: dl dt验证码 /dt dd input type=text name=verify_text id="verify_text" value="" img src=/user/verify_image alt="验证码" id="verify_code" / a href="javascript:changeCode();" 换一张/a /dd dd b验证码不正确/b/dd dd /dd /dl

js代码

复制代码 代码如下: lishixinzhi/Article/program/PHP/201311/21333

用php的CI框架怎么写登录和注册

第一步:login.php

//登陆方法

public function login(){

//如果用户名和密码为空,则返回登陆页面

if(empty($_POST['username']) || empty($_POST['password'])){

$data['verifycode'] = rand(1000,9999);//生成一个四位数字的验证码

//将验证码放入session中,注意:参数是数组的格式

$this-session-set_userdata($data);

//注意:CI框架默认模板引擎解析的模板文件中变量不需要$符号

//$this-parser-parse("admin/login",$data);

//smarty模板变量赋值

$this-tp-assign("verifycode",$data['verifycode']);

//ci框架在模板文件中使用原生态的PHP语法输出数据

//$this-load-view('login',$data);//登陆页面,注意:参数2需要以数组的形式出现

//显示smarty模板引擎设定的模板文件

$this-tp-display("admin/login.php");

}else{

$username = isset($_POST['username'])!empty($_POST['username'])?trim($_POST['username']):'';//用户名

$password = isset($_POST['password'])!empty($_POST['password'])?trim($_POST['password']):'';//密码

$verifycode = isset($_POST['verifycode'])!empty($_POST['verifycode'])?trim($_POST['verifycode']):'';//验证码

//做验证码的校验

if($verifycode == $this-session-userdata('verifycode')){

//根据用户名及密码获取用户信息,注意:参数2是加密的密码

$user_info=$this-user_model-check_user_login($username,md5($password));

if($user_info['user_id'] 0){

//将用户id、username、password放入cookie中

//第一种设置cookie的方式:采用php原生态的方法设置的cookie的值

//setcookie("user_id",$user_info['user_id'],86500);

//setcookie("username",$user_info['username'],86500);

//setcookie("password",$user_info['password'],86500);

//echo $_COOKIE['username'];

//第二种设置cookie的方式:通过CI框架的input类库

$this-input-set_cookie("username",$user_info['username'],3600);

$this-input-set_cookie("password",$user_info['password'],3600);

$this-input-set_cookie("user_id",$user_info['user_id'],3600);

//echo $this-input-cookie("password");//适用于控制器

//echo $this-input-cookie("username");//适用于控制器

//echo $_COOKIE['username'];//在模型类中可以通过这种方式获取cookie值

//echo $_COOKIE['password'];//在模型类中可以通过这种方式获取cookie值

//第三种设置cookie的方式:通过CI框架的cookie_helper.php函数库文件

//这种方式不是很灵验,建议大家采取第二种方式即可

//set_cookie("username",$user_info['username'],3600);

//echo get_cookie("username");

//session登陆时使用:将用户名和用户id存入session中

//$data['username']=$user_info['username'];

//$data['user_id']=$user_info['user_id'];

//$this-session-set_userdata($data);

//跳转到指定页面

//注意:site_url()与base_url()的区别,前者带index.php,后者不带index.php

header("location:".site_url("index/index"));

}

}else{

//跳转到登陆页面

header("location:".site_url("common/login"));

}

}

}

}

第二步:User_model.php

//cookie登陆:检测用户是否登陆,如果cookie值失效,则返回false,如果cookie值未失效,则根据cookie中的用户名和密码从数据库中获取用户信息,如果能获取到用户信息,则返回查询到的用户信息,如果没有查询到用户信息,则返回0

public function is_login(){

//获取cookie中的值

if(empty($_COOKIE['username']) || empty($_COOKIE['password'])){

$user_info = false;

}else{

$user_info=$this-check_user_login($_COOKIE['username'],$_COOKIE['password']);

}

return $user_info;

}

//根据用户名及加密密码从数据库中获取用户信息,如果能获取到,则返回获取到的用户信息,否则返回false,注意:密码为加密密码

public function check_user_login($username,$password){

//这里大家要注意:$password为md5加密后的密码

//$this-db-query("select * from ");

//快捷查询类的使用:能为我们提供快速获取数据的方法

//此数组为查询条件

//注意:关联数组

$arr=array(

'username'=$username,//用户名

'password'=$password,//加密密码

'status'=1 //账户为开启状态

);

//在database.php文件中已经设置了数据表的前缀,所以此时数据表无需带前缀

$query = $this-db-get_where("users",$arr);

//返回二维数组

//$data=$query-result_array();

//返回一维数组

$user_info=$query-row_array();

if(!empty($user_info)){

return $user_info;

}else{

return false;

}

}

第三步:其它控制器:

public function __construct(){

//调用父类的构造函数

parent::__construct();

$this-load-library('tp'); //smarty模板解析类

$this-load-helper('url'); //url函数库文件

$this-load-model("user_model");//User_model模型类实例化对象

$this-cur_user=$this-user_model-is_login();

if($this-cur_user === false){

header("location:".site_url("common/login"));

}else{

//如果已经登陆,则重新设置cookie的有效期

$this-input-set_cookie("username",$this-cur_user['username'],3600);

$this-input-set_cookie("password",$this-cur_user['password'],3600);

$this-input-set_cookie("user_id",$this-cur_user['user_id'],3600);

}

$this-load-library('pagination');//分页类库

$this-load-model("role_model");//member_model模型类

$this-load-model("operation_model");//引用operation_model模型

$this-load-model("object_model");//引用object_model模型

$this-load-model("permission_model");//引用permission_model模型

}

phpCI框架 如何去掉默认index.php

下面是去掉index.php的操作

PHP CodeIgniter(CI)去掉 index.php - Langjun - 博客园

设置访问的默认路径是在

文件下,找到

$route['default_controller'] = "index"; 默认的为welcome 改为你的访问index.php之后的参数

我的访问首页

遇到类似的问题,你可以去后盾人平台看看的哦,里面的东西不错应该能帮你解决一些不明白的问题(?′?`?)*

如何让nginx支持php的ci框架

1、修改ci框架的配置文件

修改$config['uri_protocol']值

改为:

$config['uri_protocol'] = 'PATH_INFO';

2、修改nginx配置文件,在SERVER段中添加如下代码:

location /index.php{

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_param SCRIPT_FILENAME /home/wwwroot/index.php;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_split_path_info ^(.+\.php)(.*)$;

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

include fcgi.conf;

}

如果有多个应用,如:后台应用,可以多加一段以上代码,并修改相应入口文件:

location /admin.php{

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_param SCRIPT_FILENAME /home/wwwroot/admin.php;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_split_path_info ^(.+\.php)(.*)$;

fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;

include fcgi.conf;

}

PHP CI框架修改数据的方法

CI框架下的PHP增删改查总结:

controllers下的 cquery.php文件

[php] view plain copy

?php

class CQuery extends Controller {

//构造函数

function CQuery() {

parent::Controller();

// $this-load-database();

}

function index() {

//调用model 其中train为外层文件夹 MQuery为model名称 queryList为重命名

$this-load-model('train/MQuery','queryList');

//获得返回的结果集 这里确定调用model中的哪个方法

$result = $this-queryList-queryList();

//将结果集赋给res

$this-smarty-assign('res',$result);

//跳转到显示页面

$this-smarty-view('train/vquery.tpl');

}

//进入新增页面

function addPage() {

$this-smarty-view('train/addPage.tpl');

}

//新增

function add() {

//获得前台数据

//用户名

$memberName = $this-input-post('memberName');

//密码

$password = $this-input-post('password');

//真实姓名

$userRealName = $this-input-post('userRealName');

//性别

$sex = $this-input-post('sex');

//出生日期

$bornDay = $this-input-post('bornDay');

//e_mail

$eMail = $this-input-post('eMail');

//密码问题

$question = $this-input-post('question');

//密码答案

$answer = $this-input-post('answer');

//调用model

$this-load-model('train/MQuery','addRecord');

//向model中的addRecord传值

$result = $this-addRecord-addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);

//判断返回的结果,如果返回true,则调用本页的index方法,不要写 $result == false 因为返回的值未必是false 也有可能是""

if ($result) {

$this-index();

} else {

echo "add failed.";

}

}

//删除

function deletePage() {

//获得ID

$deleteID = $this-uri-segment(4);

//调用model

$this-load-model('train/MQuery','delRecord');

//将值传入到model的delRecord方法中

$result = $this-delRecord-delRecord($deleteID);

//判断返回值

if ($result) {

$this-index();

} else {

echo "delect failed.";

}

}

//修改先查询

function changePage() {

$changeID = $this-uri-segment(4);

$this-load-model('train/MQuery','changeRecord');

$result = $this-changeRecord-changeRecord($changeID);

//将结果集赋给res

$this-smarty-assign('res',$result);

//跳转到显示页面

$this-smarty-view('train/changePage.tpl');

}

//修改

function change() {

//获得前台数据

//ID

$ID = $this-input-post('id');

//用户名

$memberName = $this-input-post('memberName');

//密码

$password = $this-input-post('password');

//真实姓名

$userRealName = $this-input-post('userRealName');

//性别

$sex = $this-input-post('sex');

//出生日期

$bornDay = $this-input-post('bornDay');

//e_mail

$eMail = $this-input-post('eMail');

//密码问题

$question = $this-input-post('question');

//密码答案

$answer = $this-input-post('answer');

//调用model

$this-load-model('train/MQuery','change');

//向model中的change传值

$result = $this-change-change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer);

//判断返回的结果,如果返回true,则调用本页的index方法,不要写 $result == false 因为返回的值未必是false 也有可能是""

if ($result) {

$this-index();

} else {

echo "change failed.";

}

}

}

models中的 mquery.php 文件

[php] view plain copy

?php

class MQuery extends Model {

//构造函数

function MQuery() {

parent::Model();

//连接数据库

$this-load-database();

}

//查询列表

function queryList() {

//防止select出的数据存在乱码问题

//mysql_query("SET NAMES GBK");

//SQL语句

$sql = "SELECT ID,member_name,sex,e_mail FROM user_info_t";

//执行SQL

$rs = $this-db-query($sql);

//将查询结果放入到结果集中

$result = $rs-result();

//关闭数据库

$this-db-close();

//将结果集返回

return $result;

}

//新增

function addRecord($memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {

//防止select出的数据存在乱码问题

//mysql_query("SET NAMES GBK");

//SQL语句

$sql = "INSERT INTO user_info_t (member_name,password,user_real_name,sex,born_day,e_mail,question,answer) " .

"VALUES ('$memberName','$password','$userRealName','$sex','$bornDay','$eMail','$question','$answer')";

//执行SQL

$result = $this-db-query($sql);

//关闭数据库

$this-db-close();

//返回值

return $result;

}

//删除

function delRecord($deleteID) {

//防止select出的数据存在乱码问题

//mysql_query("SET NAMES GBK");

$sql = "DELETE FROM user_info_t WHERE ID = $deleteID";

$result = $this-db-query($sql);

$this-db-close();

return $result;

}

//修改前查询

function changeRecord($changeID) {

//防止select出的数据存在乱码问题

//mysql_query("SET NAMES GBK");

$sql = "SELECT ID,member_name,password,user_real_name,sex,born_day,e_mail,question,answer FROM user_info_t WHERE ID = $changeID";

//执行SQL

$rs = $this-db-query($sql);

$result = $rs-row();//$result = $rs[0]

//关闭数据库

$this-db-close();

//将结果集返回

return $result;

}

//修改

function change($ID,$memberName,$password,$userRealName,$sex,$bornDay,$eMail,$question,$answer) {

//防止select出的数据存在乱码问题

//mysql_query("SET NAMES GBK");

//SQL语句

$sql = "update user_info_t set member_name = '$memberName',password = '$password', user_real_name = '$userRealName'," .

"sex = '$sex',born_day = '$bornDay',e_mail = '$eMail',question = '$question',answer = '$answer'" .

"where ID = $ID";

//执行SQL

$result = $this-db-query($sql);

//关闭数据库

$this-db-close();

//返回值

return $result;

}

}

views 下的 addPage.tpl文件

[php] view plain copy

html

head

/head

bodyform action="{{site_url url='train/cquery/add'}}" method="post"

table border='1'

tr

td用户名/td

tdinput type="text" class="text" name="memberName" id="memberName"//td

/tr

tr

td密码/td

tdinput type="text" class="text" name="password" id="password"//td

/tr

tr

td真实姓名/td

tdinput type="text" class="text" name="userRealName" id="userRealName"//td

/tr

tr

td性别/td

tdinput type="text" class="text" name="sex" id="sex"//td

/tr

tr

td出生日期/td

tdinput type="text" class="text" name="bornDay" id="bornDay"//td

/tr

tr

tde_mail/td

tdinput type="text" class="text" name="eMail" id="eMail"//td

/tr

tr

td密码问题/td

tdinput type="text" class="text" name="question" id="question"//td

/tr

tr

td密码答案/td

tdinput type="text" class="text" name="answer" id="answer"//td

/tr

/table

table

tr

tdinput type="submit" class="button" name="OK" value="提交" /

/td

/tr

/table/form

/body

/html

(责任编辑:IT教学网)

更多

推荐Mail服务器文章