当前位置: 首页>>代码示例>>PHP>>正文


PHP set_cookie函数代码示例

本文整理汇总了PHP中set_cookie函数的典型用法代码示例。如果您正苦于以下问题:PHP set_cookie函数的具体用法?PHP set_cookie怎么用?PHP set_cookie使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_cookie函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: submit

 function submit()
 {
     $data = array("css_filename" => "login", "title" => "管理后台登录", "message" => "", "messageclass" => "");
     $this->load->view("admin/Login", $data);
     if (!$_POST) {
         redirect("cp/login");
     }
     $username = $_POST["username"];
     $password = $_POST["password"];
     if ($username == "") {
         $this->_showMessage("您还未输入用户名。", 0);
         return;
     }
     if ($password == "") {
         $this->_showMessage("您的密码还未输入。", 0);
         return;
     }
     $this->load->model("Users");
     //MD5加密码
     $password = dohash($password, 'md5');
     $result = $this->Users->CheckLogin($username, $password);
     if ($result == 0) {
         $this->_showMessage("对不起,您的密码不正确,请重新输入。", 0);
     } else {
         set_cookie("username", $username, "3600", "", "/");
         set_cookie("password", $password, "3600", "", "/");
         redirect("");
     }
 }
开发者ID:huacnlee,项目名称:booklib,代码行数:29,代码来源:login.php

示例2: validate

 function validate()
 {
     $this->db->where('nic', $this->input->post('username'));
     $this->db->where('pass', md5($this->input->post('password')));
     //A checkbox to remember me after login
     $check_box = $this->input->post('rember_me');
     $query = $this->db->get('user');
     if ($query->num_rows == 1) {
         //Setup session
         foreach ($query->result() as $row) {
             //$user_level = $row->user_level;
             $username = $row->nic;
             $password = $row->pass;
             $id = $row->id;
             $first_name = $row->first;
             $last_name = $row->last;
             $data = array('username' => $username, 'id' => $id, 'name' => $name, 'user_level' => 1, 'is_logged_in' => true);
             $this->session->set_userdata($data);
         }
         //if statement for remember me
         if ($check_box == "accept") {
             $value = array('id' => $id, 'username' => $username);
             $value = serialize($value);
             $cookie = array('name' => 'loginuser', 'value' => $value, 'expire' => '2410000', 'domain' => 'mysocialnetwork.es', 'path' => '/', 'prefix' => '', 'secure' => false);
             set_cookie($cookie);
         }
         return true;
     } else {
         return false;
     }
 }
开发者ID:asbag,项目名称:codeigniter,代码行数:31,代码来源:login_model.php

示例3: login

 public function login()
 {
     if ($this->auth != NULL) {
         $this->cm_string->php_redirect("backend");
     }
     if ($this->db->count_all_results('cm_user') == 0) {
         $this->cm_string->php_redirect("backend/auth/create_manager");
     }
     $data['seo']['title'] = 'Color ME Admin';
     $data['seo']['keywords'] = '';
     $data['seo']['description'] = 'Login System of Color ME';
     if ($this->input->post('login')) {
         $post_data = $this->input->post();
         $data['post_data']['username'] = $post_data['username'];
         $data['post_data']['password'] = $post_data['password'];
         $this->form_validation->set_rules('username', 'Username', 'trim|required|regex_match[/^([a-z0-9_])+$/i]|callback__username_check');
         $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[8]|callback__password_check[' . $post_data['username'] . ']');
         if ($this->form_validation->run() == TRUE) {
             $user = $this->db->select('username,password,salt')->where(array('username' => $post_data['username']))->from('user')->get()->row_array();
             set_cookie(md5(base_url()) . 'user_logged', $this->cm_string->encrypt_cookie(json_encode($user)), time() + 7 * 24 * 3600);
             $data = array('logined' => gmdate('Y-m-d H:i:s', time() + 7 * 3600), 'ip_logging' => $_SERVER['SERVER_ADDR']);
             $this->db->where(array('username' => $post_data['username']))->update('user', $data);
             //                $this->cm_string->js_redirect('Login Success', base_url('backend/Auth/login'));
             $this->cm_string->php_redirect("backend/Auth/login");
         }
     }
     $data['template'] = 'backend/auth/login';
     $this->load->view('backend/layout/login', isset($data) ? $data : NULL);
 }
开发者ID:Kaelcao,项目名称:colorme,代码行数:29,代码来源:Auth.php

示例4: center

 function center()
 {
     $file = $this->uri->rsegment(3, '');
     $url = 'user/user_main/index';
     if ($file == 'inbox') {
         $url = 'user/message/inbox';
     }
     $rs = $this->comm->find("member", array('username' => $this->username, 'password' => $this->password), "", "userid,username,password,loginip,logintime,logintimes");
     if ($rs) {
         $logintimes = intval($rs['logintimes']) + 1;
         $udata = array('loginip' => $_SERVER['REMOTE_ADDR'], 'logintime' => $_SERVER['REQUEST_TIME'], 'lastip' => $rs['loginip'], 'lasttime' => $rs['logintime'], 'logintimes' => $logintimes);
         $this->comm->update("member", array("userid" => $rs['userid']), $udata);
         $this->load->library('encrypt');
         $hash_1 = $this->encrypt->sha1($rs['username'] . time());
         $hash_2 = $this->encrypt->sha1($rs['password'] . time());
         $username = $this->encrypt->encode($rs['username'], $hash_1);
         $password = $this->encrypt->encode($rs['password'], $hash_2);
         $this->load->helper('cookie');
         $site = $this->config->item('site');
         set_cookie('username', $username, 3600, ".{$site['site_url']}");
         set_cookie('password', $password, 3600, ".{$site['site_url']}");
         set_cookie('hash_1', $hash_1, 3600, ".{$site['site_url']}");
         set_cookie('hash_2', $hash_2, 3600, ".{$site['site_url']}");
     }
     redirect(main_url(site_url($url)));
 }
开发者ID:perfectss,项目名称:yunlian,代码行数:26,代码来源:Main.php

示例5: login

 /**
  * login
  * 
  * Phương thức đăng nhập
  * 
  * @param type $arrOutput
  * @param type $arrInput
  * @param type $strRedirect
  * @param type $strMode
  */
 function login(&$arrOutput = array(), $arrInput = array(), $strRedirect = '', $strMode = '')
 {
     // get the CI object
     $CI =& get_instance();
     $CI->load->helper('cookie');
     $CI->load->library('session');
     $CI->load->model('common_model');
     if ($strMode == 'account') {
         $CI->db->where('username', $arrInput['username']);
         $CI->db->where('password', $arrInput['password']);
         $CI->db->where('status', 1);
         $arrUserInfo = $CI->db->get('users')->row_array();
         if ($arrUserInfo != null && count($arrUserInfo) > 0) {
             if ($this->checkAllowLogin($arrUserInfo['role_id'])) {
                 if ($arrInput['remember'] == 1) {
                     set_cookie('user_id', $arrUserInfo['id'], 86500);
                 } else {
                     $CI->session->set_userdata('user_id', $arrUserInfo['id']);
                 }
                 // Update last login
                 $CI->db->where('id', $arrUserInfo['id']);
                 $CI->db->update('users', array('lastlogin' => getCurrentDt()));
                 // Redirect to admin panel
                 redirect($strRedirect);
             } else {
                 $arrOutput['errLogin'] = LTV0055;
             }
         } else {
             $arrOutput['errLogin'] = LTV0001;
         }
     }
 }
开发者ID:thaivuong90,项目名称:ban_hang,代码行数:42,代码来源:MY_login.php

示例6: loginOut

 static function loginOut()
 {
     $user = self::getLoginUser();
     $userID = MyDes::share()->encode($user->id, DES_KEY);
     self::delLoginInfo($userID);
     set_cookie(getC('LOGIN_KEY'), 0, -1);
 }
开发者ID:lingPro,项目名称:zj_web_demo,代码行数:7,代码来源:LoginService.class.php

示例7: loginFromDatabase

function loginFromDatabase($_uid)
{
    global $mysql;
    $user = $mysql->query('select * from users where ID=' . $_uid)->fetch();
    if (!$user) {
        return -1;
    }
    set_cookie($user['cookie']);
    if (isset($user['bduss'])) {
        //删除数据库里的无用列
        $mysql->query('ALTER TABLE `users` DROP `bduss`');
    }
    global $cookie_jar, $bduss;
    if (!isset($cookie_jar['BDUSS'])) {
        return false;
    }
    $bduss = $cookie_jar['BDUSS'];
    //原本想把bdstoken存进数据库,想到需要检验cookie是否合法,还是改成动态获取
    global $bdstoken;
    $bdstoken = validateCookieAndGetBdstoken();
    if (!$bdstoken) {
        $bduss = false;
        return false;
    }
    global $uid, $username, $md5;
    $uid = $_uid;
    $username = $user['username'];
    $md5 = $user['newmd5'] === '' ? false : $user['newmd5'];
    return true;
}
开发者ID:NijiharaTsubasa,项目名称:BaiduPanAutoReshare,代码行数:30,代码来源:common.php

示例8: setFlow

 function setFlow()
 {
     $this->load->database();
     //存入cookie中
     $this->load->helper('cookie');
     $yk_id = get_cookie('id');
     //获取游客id
     set_cookie('flow', '100M');
     $count = $this->db->where('id', $yk_id)->from('user_session')->count_all_results();
     //插入之前先查查游客表该游客是否被记录了
     $session_data = array('id' => $yk_id, 'flow' => '100M');
     if ($count > 0) {
         //游客已经存入表中,只是更新
         unset($session_data['id']);
         $this->db->where('id', $yk_id)->update('user_session', $session_data);
     } else {
         $this->db->insert('user_session', $session_data);
     }
     $username = $this->session->userdata['username'];
     if ($username) {
         //如果用户已经注册,则还要存入用户表
         $this->db->where('username', $username)->update('userinfo', array('flow' => '100M'));
     }
     echo 'success';
 }
开发者ID:cygjs100crew,项目名称:cygjs_fr,代码行数:25,代码来源:Welcome.php

示例9: doLogin

 public function doLogin($uid)
 {
     //登录要写cookie,内容包含uid和在线id
     $onlineId = $this->save_online_info($uid);
     $cookieCont = $this->encode_cookie($uid, $onlineId);
     set_cookie($this->cookieName, $cookieCont, $this->CI->config->item('login_expire'));
 }
开发者ID:jiangshanmeta,项目名称:jiangshanmeta.github.io,代码行数:7,代码来源:Login.php

示例10: login

 public function login()
 {
     $this->load->model('user_model', 'User');
     $this->load->model('application_model', 'Application');
     if (get_cookie("eventribe-remember-token") != "") {
         $login = $this->User->get_user_from_token(get_cookie("eventribe-remember-token"));
         $this->session->set_userdata("user", $login);
         redirect(base_url() . 'router/org_picker/' . $login);
     } else {
         $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[250]');
         $this->form_validation->set_rules('password', 'Password', 'required|min_length[5]|max_length[250]');
         //run validation
         if ($this->form_validation->run() == FALSE) {
             $this->session->set_flashdata('errors', validation_errors());
             redirect(base_url());
         } else {
             $login = $this->User->login($this->input->post('username'), $this->input->post('password'));
             if ($login != "" && $login != "invalid login parameters") {
                 $this->session->set_userdata("user", $login);
                 $this->session->set_userdata("username", $this->input->post("username"));
                 $this->session->set_userdata("password", $this->input->post("password"));
                 if ($this->input->post("remember") == 1) {
                     $token = $this->User->set_remember_me($this->input->post("username"), $this->input->post("password"));
                     $expire = time() + 2678400;
                     $cookie = array('name' => 'eventribe-remember-token', 'value' => $token, 'expire' => $expire, 'secure' => TRUE);
                     set_cookie($cookie);
                 }
                 redirect(base_url() . 'router/org_picker/' . $login);
             } else {
                 $this->session->set_flashdata('errors', $login);
                 redirect(base_url());
             }
         }
     }
 }
开发者ID:Omar-Faramawi,项目名称:codeigniter-eventrib-project,代码行数:35,代码来源:router.php

示例11: logout

 public function logout()
 {
     $this->load->helper('cookie');
     set_cookie('menu_url', '', time() - 3600);
     $this->session->sess_destroy();
     successRedirct('backend/user/login', "退出成功!");
 }
开发者ID:zhupengfei365,项目名称:backend.hc.com,代码行数:7,代码来源:User.php

示例12: space_count

 public function space_count()
 {
     $uid = (int) $this->input->get('uid');
     if ($this->uid && $uid && $this->uid != $uid) {
         // 记录访客信息
         $name = 'space-count-' . $this->uid . '-' . $uid;
         if (get_cookie($name)) {
             // 缓存期
         } else {
             // 查询今天是否访问过
             if ($this->db->where('uid', $this->uid)->where('spaceid', $uid)->where('DATEDIFF(from_unixtime(inputtime),now())=0')->count_all_results('space_access')) {
                 $this->db->where('uid', $this->uid)->where('spaceid', $uid)->update('space_access', array('inputtime' => SYS_TIME));
             } else {
                 $this->db->insert('space_access', array('uid' => $this->uid, 'spaceid' => $uid, 'content' => '', 'username' => $this->member['username'], 'inputtime' => SYS_TIME));
             }
             set_cookie($name, SYSTIME, 300);
             // 5分钟统计一次
         }
     }
     // 验证空间权限
     if ($this->_space_show($uid)) {
         $callback = isset($_GET['callback']) ? $_GET['callback'] : 'callback';
         exit($callback . '(' . json_encode(array('url' => dr_member_url('api/access', array('uid' => $uid)))) . ')');
     }
     exit('');
 }
开发者ID:Thebeautifullife,项目名称:yichunchengguan,代码行数:26,代码来源:Api.php

示例13: skins

 public function skins()
 {
     $skin = $this->input->get_post('skin', TRUE);
     $skin = $skin ? $skin : 'green';
     set_cookie('skin', $skin, 120000);
     die('{"status":200,"msg":"success"}');
 }
开发者ID:Neo-Luo,项目名称:amc,代码行数:7,代码来源:settings.php

示例14: login

 public function login()
 {
     $username = $this->input->post('username');
     $password = $this->input->post('password');
     $remember_check = $this->input->post('remember_check');
     if (isset($remember_check)) {
         set_cookie('ck_username', $username, time() + 60);
         set_cookie('ck_password', $password, time() + 60);
         set_cookie('ck_remember', $remember_check, time() + 60);
     } else {
         delete_cookie('ck_username');
         delete_cookie('ck_password');
         delete_cookie('ck_remember');
     }
     $salt = '$2a$04$123456789123456789123$';
     $hashed_password = crypt($password, $salt);
     $where_arr = array('admin_name' => $username, 'admin_pass' => $hashed_password);
     $query = $this->db->get_where("tbl_admin", $where_arr);
     $row = $query->row_array();
     //คิวรี่ข้อมูลมาแสดงแค่รายการเดียว
     if (isset($row)) {
         $newdata = array('ses_admin_id' => $row['admin_id'], 'ses_admin_name' => $row['admin_name']);
         $this->session->set_userdata($newdata);
         // อัพเดทข้อมูลการล็อกอินของ admin เช่น ล็อกอินล่าสุด
         $update_data = array('admin_lastlogin	' => date("Y-m-d H:i:s"));
         $this->db->update('tbl_admin', $update_data, array('admin_id' => $row['admin_id']));
     }
     redirect('admin');
     // ไปหน้า admin
 }
开发者ID:phannack,项目名称:Learn-CodeIgniter,代码行数:30,代码来源:Admin.php

示例15: mobile_detect

 function mobile_detect()
 {
     if (!INSTALL_MODULE_DONE) {
         return false;
     }
     $CI =& get_instance();
     $CI->load->helper('cookie');
     $mobile_detect = filter_input(INPUT_GET, 'mobile_detect');
     if (empty($mobile_detect)) {
         $mobile_detect = filter_input(INPUT_COOKIE, 'mobile_detect');
     } elseif ('denied' === $mobile_detect) {
         // Back from the mobapp
         set_cookie(array('name' => 'mobile_detect', 'value' => 'denied', 'expire' => time() + '86500', 'domain' => COOKIE_SITE_SERVER, 'path' => '/' . SITE_SUBFOLDER));
         return false;
     }
     if ('denied' === $mobile_detect || !$CI->pg_module->is_module_installed('mobile') || $CI->router->is_api_class || !$CI->pg_module->get_module_config('mobile', 'use_mobile_detect')) {
         return false;
     } else {
         $CI->load->library('mobile_detect');
         if ($CI->mobile_detect->isMobile()) {
             set_cookie(array('name' => 'mobile_detect', 'value' => 'ask', 'expire' => time() + '86500', 'domain' => COOKIE_SITE_SERVER, 'path' => '/' . SITE_SUBFOLDER));
             redirect($CI->pg_module->get_module_config('mobile', 'app_url') . '/#!/redirect');
         }
         return true;
     }
 }
开发者ID:Calit2-UCI,项目名称:IoT_Map,代码行数:26,代码来源:post_controller_constructor-mobile_detect.php


注:本文中的set_cookie函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。