CI中获取HTTP头信息的方法:

$this->input->request_headers()

在不支持apache_request_headers()的非Apache环境非常有用。返回请求头(header)数组。

$headers = $this->input->request_headers();

----------------------------------------------------------------------------------------------

获取http请求的头信息。

PHP手册提供了现成的函数:

getallheaders

(PHP 4, PHP 5)

getallheaders — Fetch all HTTP request headers

说明

array getallheaders ( void )

Fetches all HTTP headers from the current request.

This function is an alias for apache_request_headers(). Please read theapache_request_headers() documentation for more information on how this function works.

返回值

An associative array of all the HTTP headers in the current request, orFALSE on failure.

Example #1 getallheaders() example

 

  1. <?php
  2. foreach (getallheaders() as $name => $value) {
  3. echo "$name: $value\n";
  4. }
  5. ?>

不过这个函数只能在apache环境下使用,iis或者nginx并不支持,可以通过自定义函数实现

  1. <?php
  2. <span class="html">if (!function_exists('getallheaders'))
  3. {
  4. function getallheaders()
  5. {
  6. foreach ($_SERVER as $name => $value)
  7. {
  8. if (substr($name, 0, 5) == 'HTTP_')
  9. {
  10. $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
  11. }
  12. }
  13. return $headers;
  14. }
  15. }</span>
  16. ?>

好了,看看都打印出了啥吧

  1. <?php
  2. print_r(getallheaders());

获得结果:

    1. Array
    2. (
    3. [Accept] => */*
    4. [Accept-Language] => zh-cn
    5. [Accept-Encoding] => gzip, deflate
    6. [User-Agent] => Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727)
    7. [Host] => localhost
    8. [Connection] => Keep-Alive
    9. )

PHP获取http头信息和CI中获取HTTP头信息的方法的更多相关文章

  1. 从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法

    原文:从加载DLL的中获取放置于Resources文件夹中资源字典的几种方法 主程序 为 Main_Test.exe 被加载的DLL 为 Load_Test.dll  此DLL 中 有一个 文件夹Re ...

  2. CI中获取读操作的结果集行数+获取写操作的影响行数

    本质:读操作,用mysql_num_rows函数,写操作用mysql_affected_rows函数 mysql_num_rows() 返回结果集中行的数目.此命令仅对 SELECT 语句有效.要取得 ...

  3. 微信小程序编译包的获取与解压——在手机中获取小程序编译包wxapkg

    准备工作: 微信关注需要下载编译包的小程序,然后点进去看一下,微信就会自动下载相应的编译包到手机上了. 获取小程序编译包: 据说root手机可以直接在手机的文件管理中查找wxapkg文件,自己尝试了下 ...

  4. Web项目中获取SpringBean——在非Spring组件中获取SpringBean

    最近在做项目的时候我发现一个问题:Spring的IOC容器不能在Web中被引用(或者说不能被任意地引用).我们在配置文件中让Spring自 动装配,但并没有留住ApplicationContext的实 ...

  5. Python时间获取详解,Django获取时间详解,模板中获取时间详解(navie时间和aware时间)

    1.Python获取到的时间 import pytz from datetime import datetime now = datetime.now() # 这个时间为navie时间(自己不知道自己 ...

  6. JS/jquery获取iframe内部元素和ifame中获取外部元素精华

    1.从外部获取iframe内部元素方法: js : window.frames['frame'].document.getElementById("imglist");   //f ...

  7. 【修改帐号信息】Eclipse中修改SVN用户名和密码方法

    由于在svn 的界面中并没有为我们提供直接更换用户名密码的地方,所以一旦我们需要更换用户名的就需要自己想一些办法. 解决方案: 在Eclipse 使用SVN 的过程中大多数人往往习惯把访问SVN 的用 ...

  8. 练习 map集合被使用是因为具备映射关系 "进度班" "01" "张三" "进度班" "02" "李四" "J1701" "01" "王五" "J1701" "02" "王二" 此信息中,我们要怎样把上述信息装入集合中, 根据班级信息的到所有的所有信

    package com.rf.xs; import java.util.Arrays; public class Student01 { String name; int age; public St ...

  9. ios中从相册:相机中获取图片信息

    ios中从相册/相机中获取图片信息 从相册中获取图片的信息 UIImagePickerController *imgPickView = [[UIImagePickerController alloc ...

随机推荐

  1. 应用程序域(Application Domain)

    应用程序域为隔离正在运行的应用程序提供了一种灵活而安全的方法. 应用程序域通常由运行时宿主创建和操作. 有时,您可能希望应用程序以编程方式与应用程序域交互,例如想在不停止应用程序运行的情况下卸载某个组 ...

  2. bzoj 1054 移动玩具

    题目连接 http://www.lydsy.com/JudgeOnline/problem.php?id=1054 移动玩具 Description 在一个4*4的方框内摆放了若干个相同的玩具,某人想 ...

  3. 58.xilinx原语DCM,PLL的使用

    DCM_BASE 基本数字时钟管理模块的缩写,是相伴和频率可配置的数字锁相环电路,常用于FPGA系统中复杂的时钟管理.如需要频率和相位动态配置,则可以选用DCM_ADV原语,如需要相位动态偏移,可使用 ...

  4. Android实现简单音乐播放器(MediaPlayer)

    Android实现简单音乐播放器(MediaPlayer) 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个简单的音乐播放器,要求功能 ...

  5. UIImageView swift

    // // ViewController.swift // UILabelTest // // Created by mac on 15/6/23. // Copyright (c) 2015年 fa ...

  6. (转)Unity3d中的属性(Attributes)整理

    Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了.其它倒没什么需要注意的.本文将所有运行属性过一遍罢了. using UnityEngine; using ...

  7. 修改Input中Placeholder默认提示颜色(兼容)

    input::-webkit-input-placeholder, textarea::-webkit-input-placeholder { color: #f00; } input:-moz-pl ...

  8. ubuntu mysql 使用

    环境:ubuntu 12.04.5    mysql-server-5.5 安装:sudo apt-get install mysql-server-5.5 (服务端 第一台虚拟机) sudo apt ...

  9. python-面向对象(股票对象举例)

    股票对象实例 class Stock(object): def __init__(self,stockCode ,stockName,averagePrice_yesterday,averagePri ...

  10. css中的border还可以这样玩

    在看这篇文章之前你可能会觉得border只是简单的绘制边框,看了这篇文章,我相信你也会跟我一样说一句"我靠,原来css中的border还可以这样玩".这篇文章主要是很早以前看了别人 ...