PHP如何获取表单的POST数据呢?本文介绍3种获取POST数据的方法,并将代码附上,希望可以帮助到你。
一、PHP获取POST数据的几种方法
方法1、最常见的方法是:$_POST['fieldname'];
说明:只能接收Content-Type: application/x-www-form-urlencoded提交的数据
解释:也就是表单POST过来的数据
方法2、file_get_contents(“php://input”);
说明:
允许读取 POST 的原始数据。
和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。
php://input 不能用于 enctype=”multipart/form-data”。
解释:
对于未指定 Content-Type 的POST数据,则可以使用file_get_contents(“php://input”);来获取原始数据。
事实上,用PHP接收POST的任何数据都可以使用本方法。而不用考虑Content-Type,包括二进制文件流也可以。
所以用方法二是最保险的方法。
方法3、$GLOBALS['HTTP_RAW_POST_DATA'];
说明:
总是产生 $HTTP_RAW_POST_DATA 变量包含有原始的 POST 数据。
此变量仅在碰到未识别 MIME 类型的数据时产生。
$HTTP_RAW_POST_DATA 对于 enctype=”multipart/form-data” 表单数据不可用
如果post过来的数据不是PHP能够识别的,可以用 $GLOBALS['HTTP_RAW_POST_DATA']来接收,
比如 text/xml 或者 soap 等等
解释:
$GLOBALS['HTTP_RAW_POST_DATA']存放的是POST过来的原始数据。
$_POST或$_REQUEST存放的是 PHP以key=>value的形式格式化以后的数据。
但$GLOBALS['HTTP_RAW_POST_DATA']中是否保存POST过来的数据取决于centent-Type的设置,即POST数据时 必须显式示指明Content-Type: application/x-www-form-urlencoded,POST的数据才会存放到 $GLOBALS['HTTP_RAW_POST_DATA']中。
二、演示
1、PHP 如何获取POST过来的XML数据和解析XML数据
比如我们在开发微信企业号时,如何处理用户回复过来的数据呢?
文档:http://qydev.weixin.qq.com/wiki/index.php?title=%E6%8E%A5%E6%94%B6%E6%99%AE%E9%80%9A%E6%B6%88%E6%81%AF
首先查阅文档,可知道:启用开发模式后,当用户给应用回复信息时,微信服务端会POST一串XML数据到已验证的回调URL
假设该URL为 http://www.xxx.com
Http请求方式: POST
http://www.xxx.com/?msg_signature=ASDFQWEXZCVAQFASDFASDFSS×tamp=13500001234&nonce=123412323
POST的XML内容为:
<xml> <ToUserName><![CDATA[toUser]]></ToUserName> <FromUserName><![CDATA[fromUser]]></FromUserName> <CreateTime>1348831860</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[this is a test]]></Content> <MsgId>1234567890123456</MsgId> <AgentID>1</AgentID> </xml>
那么怎么接收这段内容呃?
这时就可以用到:方法2(file_get_contents(“php://input”))、方法3($GLOBALS['HTTP_RAW_POST_DATA'])
方法2(file_get_contents(“php://input”)):
$input = file_get_contents("php://input"); //接收POST数据
$xml = simplexml_load_string($input); //提取POST数据为simplexml对象
var_dump($xml);
方法3($GLOBALS['HTTP_RAW_POST_DATA'])
$input = $GLOBALS['HTTP_RAW_POST_DATA']; libxml_disable_entity_loader(true); $xml = simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA); var_dump($xml);
PHP获取POST数据的3种方法及其代码分析,希望可以帮到你。
Apple’s newest devices feature the Retina Display, a screen that packs double as many pixels into the same space as older devices. For designers this immediately brings up the question, “What can I do to make my content look outstanding on these new iPads and iPhones?”. First there are a few tough questions to consider, but then this guide will help you get started making your websites and web apps look amazingly sharp with Retina images!

Things to Consider When Adding Retina Images
The main issue with adding retina images is that the images are double as large and will take up extra bandwidth (this won’t be an issue for actual iOS apps, but this guide is covering web sites & web apps only). If your site is mostly used on-the-go over a 3G network it may not be wise to make all your graphics high-definition, but maybe choose only a select few important images. If you’re creating something that will be used more often on a WI-FI connection or have an application that is deserving of the extra wait for hi-res graphics these steps below will help you target only hi-res capable devices.
Simple Retina Images
The basic concept of a Retina image is that your taking a larger image, with double the amount of pixels that your image will be displayed at (e.g 200 x 200 pixels), and setting the image to fill half of that space (100 x 100 pixels). This can be done manually by setting the height and width in HTML to half the size of your image file.
<img src="my200x200image.jpg" width="100" height="100">
If you’d like to do something more advanced keep reading below for how you can apply this technique using scripting.
Creating Retina Icons for Your Website
When users add your website or web app to their homescreen it will be represented by an icon. These sizes for regular and Retina icons (from Apple) are as follows:
![]()
| iPhone | 57 x 57 |
|---|---|
| Retina iPhone | 114 x 114 |
| iPad | 72 x 72 |
| Retina iPad | 144 x 144 |
For each of these images you create you can link them in the head of your document like this (if you want the device to add the round corners remove -precomposed):
<link href="touch-icon-iphone.png" rel="apple-touch-icon-precomposed" />
<link href="touch-icon-ipad.png" rel="apple-touch-icon-precomposed" sizes="72x72" />
<link href="touch-icon-iphone4.png" rel="apple-touch-icon-precomposed" sizes="114x114" />
<link href="touch-icon-ipad3.png" rel="apple-touch-icon-precomposed" sizes="144x144" />
If the correct size isn’t specified the device will use the smallest icon that is larger than the recommended size (i.e. if you left out the 114px the iPhone 4 would use the 144px icon).
Retina Background Images
Background images that are specified in your CSS can be swapped out using media queries. You’ll first want to generate two versions of each image. For example ‘bgPattern.png’ at 100px x 100px and ‘bgPattern@2x.png’ at 200px x 200px. It will be useful to have a standard naming convention such as adding @2x for these retina images. To add the new @2x image to your site simply add in the media query below (You can add any additional styles that have background images within the braces of the same media query):
.repeatingPattern {
background: url(../images/bgPattern.png) repeat;
background-size: 100px 100px;
}
@media only screen and (-webkit-min-device-pixel-ratio: 2) {
.repeatingPattern {
background: url(../images/bgPattern@2x.png) repeat;
}
}
JavaScript for Retina Image Replacement
For your retina images that aren’t backgrounds the best option seems to be either creating graphics with CSS, using SVG, or replacing your images with JavaScript. Just like the background images, you’ll want to create a normal image and one ‘@2x’ image. Then with JavaScript you can detect if the pixel ratio of the browser is 2x, just like you did with the media query:
if (window.devicePixelRatio == 2) {
//Replace your img src with the new retina image
}
If you’re using jQuery you could quickly replace all your images like this very basic example below. It’s a good idea to add a class to identify the images with hi-res versions so you don’t replace any others by mistake. I’ve added a class=”hires” for this example. Also make sure you have the standard (non-retina) image height and width set in the HTML:
<img class="hires" alt="" src="search.png" width="100" height="100" />
<script type="text/javascript">
$(function () {
if (window.devicePixelRatio == 2) {
var images = $("img.hires");
// loop through the images and make them hi-res
for(var i = 0; i < images.length; i++) {
// create new image name
var imageType = images[i].src.substr(-4);
var imageName = images[i].src.substr(0, images[i].src.length - 4);
imageName += "@2x" + imageType;
//rename image
images[i].src = imageName;
}
}
});
</script>
Server-Side Retina Images
If you’d like to implement a server-side retina image solution, I recommend checking out Jeremy Worboys’ Retina Images (which he also posted in the comments below). His solution uses PHP code to determine which image should be served. The benefit of this solution is that it doesn’t have to replace the small image with the retina one so you’re using less bandwidth, especially if you have lots of images that you’re replacing.
Website Optimization for Retina Displays
If you’re looking for additional information on creating Retina images, I’ve recently had a short book published called Website Optimization for Retina Displays that covers a range of related topics. It contains some of what is above, but also includes samples for many different situations for adding Retina images. It explains the basics of creating Retina images, backgrounds, sprites, and borders. Then it talks about using media queries, creating graphics with CSS, embedding fonts, creating app icons, and more tips for creating Retina websites.
版本区别
| 功能特性 | Windows RT | Windows 8 (标准版) |
Windows8 Pro (专业版) |
Windows 8 Enterprise (企业版) |
| 与现有Windows 兼容 | 无 | 有 | 有 | 有 |
| 购买渠道 | 在设备上预装 | 大多数渠道 | 大多数渠道 | 经过认证的客户 |
| 架构 | ARM (32-bit) | IA-32 (32-bit) or x86-64 (64-bit) | IA-32 (32-bit) or x86-64 (64-bit) | IA-32 (32-bit) or x86-64 (64-bit) |
| 安全启动 | 有 | 有 | 有 | 有 |
| 图片密码 | 有 | 有 | 有 | 有 |
| 开始界面、动态磁帖以及相关效果 | 有 | 有 | 有 | 有 |
| 触摸键盘、拇指键盘 | 有 | 有 | 有 | 有 |
| 语言包 | 有 | 有 | 有 | 有 |
| 更新的资源管理器 | 有 | 有 | 有 | 有 |
| 标准程序 | 有 | 有 | 有 | 有 |
| 文件历史 | 有 | 有 | 有 | 有 |
| 系统的重置功能 | 有 | 有 | 有 | 有 |
| Play To “播放至”功能 | 有 | 有 | 有 | 有 |
| Connected standby保持网络连接的待机 | 有 | 有 | 有 | 有 |
| Windows Update | 有 | 有 | 有 | 有 |
| Windows Defender | 有 | 有 | 有 | 有 |
| 增强的多显示屏支持 | 有 | 有 | 有 | 有 |
| 新的任务管理器 | 有 | 有 | 有 | 有 |
| ISO 镜像 and VHD 挂载 | 有 | 有 | 有 | 有 |
| 移动通信功能 | 有 | 有 | 有 | 有 |
| Microsoft 账户 | 有 | 有 | 有 | 有 |
| Internet Explorer 10 | 有 | 有 | 有 | 有 |
| SmartScreen | 有 | 有 | 有 | 有 |
| Windows 商店 | 有 | 有 | 有 | 有 |
| Xbox Live 程序 (包括 Xbox Live Arcade) | 有 | 有 | 有 | 有 |
| Exchange ActiveSync | 有 | 有 | 有 | 有 |
| 快速睡眠(snap) | 有 | 有 | 有 | 有 |
| VPN连接 | 有 | 有 | 有 | 有 |
| Device encryption | 有 | 无 | 无 | 无 |
| 随系统预装的Microsoft Office | 有 | 无 | 无 | 无 |
| 桌面 | 部分 | 有 | 有 | 有 |
| 储存空间管理(storage space) | 无 | 有 | 有 | 有 |
| Windows Media Player | 无 | 有 | 有 | 有 |
| Windows Media Center | 无 | 无 | 需另行添加 | 无 |
| 远程桌面 | 只作客户端 | 只作客户端 | 客户端和服务端 | 客户端和服务端 |
| 从VHD启动 | 无 | 无 | 有 | 有 |
| BitLocker and BitLocker To Go | 无 | 无 | 有 | 有 |
| 文件系统加密 | 无 | 无 | 有 | 有 |
| 加入Windows 域 | 无 | 无 | 有 | 有 |
| 组策略 | 无 | 无 | 有 | 有 |
| AppLocker | 无 | 无 | 有 | 有 |
| Hyper-V | 无 | 无 | 仅64bit支持 | |
| Windows To Go | 无 | 无 | 无 | 有 |
| DirectAccess | 无 | 无 | 无 | 有 |
| 分支缓存(BranchCache) | 无 | 无 | 无 | 有 |
| 以RemoteFX提供视觉特效 | 无 | 无 | 无 | 有 |
| Metro风格程序的部署 | 无 | 无 | 无 | 有 |
下载地址
根据下面的 SHA1 或文件名在网上搜索下载地址,下载完成后验证其 SHA1 即可。
Windows 8 (x86) - DVD (Chinese-Simplified)
文件名: cn_windows_8_x86_dvd_915414.iso
SHA1: 0C4A168E37E38EFB59E8844353B2535017CBC587
Windows 8 (x64) - DVD (Chinese-Simplified)
文件名: cn_windows_8_x64_dvd_915407.iso
SHA1: A87C4AA85D55CD83BAE9160560D1CB3319DD675C
Windows 8 Pro VL (x86) - DVD (Chinese-Simplified)
文件名: cn_windows_8_pro_vl_x86_dvd_917720.iso
SHA1: EEEF3C3F6F05115C7F7C9C1D19D6A6A6418B5059
Windows 8 Pro VL (x64) - DVD (Chinese-Simplified) 推荐
文件名: cn_windows_8_pro_vl_x64_dvd_917773.iso
SHA1: 9C4EC9FC4FB561F841E22256BC9DEA6D9D6611FF
Windows 8 Enterprise (x86) - DVD (Chinese-Simplified)
文件名: cn_windows_8_enterprise_x86_dvd_917682.iso
SHA1: 951565D8579C5912FB4A407B3B9F715FBDB77EFE
Windows 8 Enterprise (x64) - DVD (Chinese-Simplified)
文件名: cn_windows_8_enterprise_x64_dvd_917570.iso
SHA1: 1280BC3A38A7001FDE981FA2E465DEB341478667
激活方式
目前流行 KMSmicro 激活,写此文时的最新版本是 4.0,下载地址网上搜之(或联系我)。
evasi0n 是由 pod2g、planetbeing、pimskeks、肌肉男四名黑客组成的 evad3rs 越狱梦之队发布的 iOS6 完美越狱工具。可以完美越狱 iOS6.0、iOS6.0.1、iOS6.0.2、iOS6.1、iOS6.1.1 和 iOS6.1.2 等多个固件版本的所有 iOS6 设备(AppleTV 除外)。
下载地址:http://evasi0n.com/
最近开发了一款 iPhone 客户端应用,提交到 App Store,被拒绝(Rejected)。然后修复问题后再次提交,仍然被拒绝,奇怪的是 Resolution Center 中的拒绝原因跟上次一模一样。
幸好我在应用中做了记录客户端信息的功能,查看后发现,IP 来自“美国Apple公司”的启动版本竟然是第一次提交的版本。于是我登录 iTunes Connect 跟苹果客服联系,对方回复他们打开的确实是有问题那个版本。
正当迷茫之时,无意中在 iTunes Connect 看到 Binary Details 这个按钮,点进去一看明白了。原来,虽然我在 Xcode 中重新上传了源文件,但是这里看到的仍然是旧版本。于是我点右上角的“Reject This Binary”按钮,重新通过 Xcode 上传源代码,过会儿再进入 Binary Details 查看,还是没有变化。苦恼中。
是不是 Xcode 中要做什么处理呢?我是新手,只知道点菜单栏上的三角形按钮是调试,具体要怎么使用 Debug / Release / Run / Test / Profile / Analyze / Archive 还真是不太明白,于是对这些功能一阵乱点,意外发现 Organizer 的 Archives 中项目的 Creation Data 变成了刚才的时间,而且下面也多了一条记录,赶紧 Distribute!
一柱香后再回头去看看 Binary Details,终于看到新版本的信息了。
Waiting For Review 中……
做网页的朋友应该都知道常用的几个HTML转义符,如“ ”表示空格,“>”表示“>”等,但是有时候我们为了网页的文字不被搜索引擎收录,比如评论信息,这时可以用同样的方法去转义汉字等各种字符,一般格式为 "&#"+ASCII+";",如“中华人民共和国”可以转义为“中华人民共和国”。
在C#中可以这样来实现:
private string htmlEscape(string s)
{
StringBuilder sb = new StringBuilder();
foreach (char c in s)
{
sb.Append("&#" + (int)c + ";");
}
return sb.ToString();
}
支付宝(www.alipay.com)的产生的确对于促进网络支付的确起到了很大的推动作用,笔者就在目前自己使用支付宝API接口开发中,遇到的一些问题,解决办法,做了简短的记录,由此与大家共分享,由于作者水平有限,难免出现错误,请大家指出,谢谢。
目前,申请支付宝接口主要有两种方式,1.免费接口,淘宝抽取手续费2%;2.付费接口,比如600元允许48000元交易金额的配额等,笔者使用的是前者,免费接口。在免费接口中,又分为两种,标准双接口交易类型和即时到账交易,这两种支付方式中,前者为淘宝担保交易+即时到账交易,而后者仅仅为即时到账交易,可根据自己的需要进行申请。
具体申请的过程在这里就不赘述了,如有需要,可以通过留言的方式,我会告知您。
支付接口申请成功后,会的到两个重要的参数支付宝安全校验码(key)和合作伙伴id(partner),这两个参数起到了支付是否成功的重要作用,申请成功后,都可以在支付宝后台商家工具中获得。
支付宝的原理其实就是通过浏览器传参数到支付网关(https://www.alipay.com/cooperate/gateway.do),支付网关是由Struts构建的,笔者感觉是通过ActionForm获得浏览器参数,进行内部解析的,浏览器传的参数都进过了MD5加密处理。
笔者遇到的第一个问题:
HAS_NO_PRIVILEGE,在官方给出的API介绍中是这样解释的:“该错误提示的是,您没有使用该接口的权限,那么登陆自己的支付宝账户,商家工具,查看实物交易服务或者虚拟物品交易服务,如果没有申请,请立刻申请并且当时开通。”我很肯定的是我已经开通了服务,那么问题就不是出在这儿,仔细查阅了API发现,在service的参数中,设置错误了,所以,在以后的开发中请注意,如果您选择的是:
标准双接口交易->service=trade_create_by_buyer
即时到帐交易->service=create_direct_pay_by_user
这里一定要填写正确,否则就会出现没有权限这样的问题,这里请注意一下。
笔者遇到的第二个问题:
支付成功了,但是总是返回的错误页面,首先请看下面的代码:
//生成Md5摘要;
string mysign = GetMD5(prestr.ToString(), _input_charset);
string sign = Request.QueryString["sign"];
if (mysign == sign && responseTxt =="true") //验证支付发过来的消息,签名是否正确
{
Response.Write("success"); //返回给支付宝消息,成功
}
else
{
Response.Write("fail");
}这里如果mysign和responseTxt为flase,则会显示错误信息,这是由于在Return页面中,没有设置支付宝安全校验码(key)和合作伙伴id(partner),解决方法,在page_lode中加入常量:
String key = "xxxxxxxxxxxxxxxxx";//你的安全效验码
String partner = "xxxxxxxxxxxxxx";//你的合作伙伴id;
这样,加入后,当付款成功时,就会返回到正确的Success了!
笔者使用的是.net版的支付方式,Java版也许会有所不同,不过原理应该和这个是一样的,我已经下载了官方给出的Java实例,待看后与大家分享经验心得。
Extension MIME Type
.xaml application/xaml+xml
.xap application/x-silverlight-app
WPF和ClickOne应用程序的支持,那么还需要添加下表中的MIME类型:
Extension MIME Type
.manifest application/manifest
.application application/x-ms-application
.xbap application/x-ms-xbap
.deploy application/octet-stream
.xps application/vnd.ms-xpsdocument
<INPUT onfocus="oRng=this.createTextRange();oRng.collapse(true);oRng.moveStart('character',3);oRng.select()" value=abcdefg type=text name=text1>
当焦点移至文本框时光标定位在位置3。
如果要直接定位在文本末尾,把上面的数字 3 改为 this.value.length 即可。
--------------------
常量:
整型,实型,布尔值,字符串型,null,undefined
变量:var
--------------------
除法运算:9/4 = 2.25 (而不是2)
--------------------
系统函数:
1,encodeURI URL编码
var urlStr=encodeURI("http://www.abc.com/?country=吴&name=z x");
结果:http://www.abc.com/?country=%E5%90%B4&name=z%20x
2,decodeURI URL解码
3,parseInt 将字符串按指定进制转换成一个整数,参数二表示进制
parseInt("32",10) 结果:32
parseInt("3c2",10) 结果:3
parseInt("c32",10) 结果:NaN
parseInt("0x18",10) 结果:0
parseInt("12",16) 结果18
4,parseFloat 将字符串转成小数
parseFloat("2.5") 结果:2.5
parseFloat("2.c5") 结果:2
parseFloat("c2.5") 结果:NaN
5,isNaN 用于检测parseInt和parseFloat返回是否为NaN
返回true/false
6,escape 编码
非ASCII替换为%xx
7,unescape 解码
8,eval 将字符串作为JS表达式执行,例
for(var i=0;i<3;i++) eval("var a"+i+"="+i);
相当于:
var a0=0; var a1=1; var a2=2;
--------------------
对象
1,Object
2,String
方法:
indexOf,
lastIndexOf,
match,使用正则表达式模式对字符串执行搜索,返回包含该搜索结果的数组
replace,
search,使用正则表达式搜索,第一个匹配的字符的位置
slice,截字符串:参数一,开始位置,参数二,结束位置(不指定或为-1时表示末位置)
split,返回一个字符串按照某种分隔标志符拆分为若干子字符串时所产生的字符串数组,分隔符可以是多个字符或一个正则表达式,它不作为任何数组元素的一部分返回。
substr,截字符串:参数一,开始位置,参数二,长度
toLowerCase,
toUpperCase,
3,Math(不能用new创建)
方法:
abs,绝对值
sin,cos,正余弦
asin,acos,反正余弦
random,返回介于0~1之间的伪随机数
例:var num = Math.randow();
4,Date
var currentTime=new Date();
//var currentTime=new Date(2002,3,4);
var strDate=currentTime.getYear()+"年";
strDate+=currentTime.getMonth()+"月";
strDate+=currentTime.getDate()+"日";
strDate+=currentTime.getHours()+":";
strDate+=currentTime.getMinutes()+":";
strDate+=currentTime.getSeconds()+" ";
strDate+=currentTime.getMilliseconds();
alert(strDate);
结果:2008年1月19日15:27:10 518
----------------------
数组
1,
var arr=["abc",123,'abc',,3.4];
for(var i=0;i<arr.length;i++)
{
alert(arr[i]);
}
2,用对象的方式实现数组
function MyArray(){this.length=arguments.length;for(var i=0;....
3,Array对象
var arr=new Array(2.4,"abc",2);
arr.sort(); //排序
alert的结果为 2 2,4 abc
-----------------------