dongyinju5977 2014-07-09 13:10
浏览 36

在codeigniter中设置cookie

i am tring to set cookie in codeigniter but i cannt make it happen i dont know what is wrong. there is no error on the error log page...

this is my view page...

<!DOCTYPE html>
<html>
    <head>
        <title>
            EKART
        </title>
    </head>
    <body>
    <h1>SIGN IN</h1>
    <form id="admin" action="/do/ekart/adminlogin/login/" method="POST">
    Name :<br/>
    <input type="text" name="name" id="name"/><div id="name_display"></div><br/>    
    Password :<br/>
    <input type="password" name="password" id="pasword"/><div id="password_display"></div><br/> 

    <input type="submit" value="Submit"/>   
    </form>
    </body>
</html>

and here is my controller..

adminlogin.php

  <?php
    class adminlogin extends Controller{
        public function __construct(){
            parent::Controller();
            $this->load->library('mylib');
        }
        public function index(){
            $this->load->view("ekart/adminlogin");      
        }
        public function login(){
            $name=$_POST["name"];
            $password=$_POST["password"];
            $data=array("username"=>$name,"password"=>$password);
            $result=$this->mylib->logincheck($data);
            if($result){
                echo "every thing is fine";
                setcookie("myCookie",$name,time()+3600,"/");
                $this->load->view("ekart/home",array("message"=>""));
            }
        }
    }

the control is going inside if and it also prints "every thing is fine" the home page is also get loaded but i dont know why the cooke is still not set..

mylib is my library to check login validation....

  • 写回答

1条回答 默认 最新

  • drnf09037160 2014-07-09 13:16
    关注

    There is a codeigniter way of doing this.

    Make sure to have $this->load->helper('cookie'); in your controller, or autoload it.

    $cookie = array(
      "username" => $name,
      "time" => time()+3600
    );
    
    $this->input->set_cookie($cookie);
    
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装