PHP中采用POST方式发送数据
最近两天项目需要,由于服务器正在开发,客户端进度稍快一些,没有服务器进行联调。因此我重操旧业,用PHP快速的写了一些web页面,算是当测试桩程序了,七八个web接口,基本上5到6个小时搞定了。由于当前的服务器需要与其他服务器进行对接,因此写的这个web服务还需要充当client角色,向其他服务器发送请求。
在网上搜了一下,基本上两种方法:(转自网友文章)
1.通过curl函数
$post_data
=
array
()
;
$post_data
[
'
clientname
'
]
=
"
test08
"
;
$post_data
[
'
clientpasswd
'
]
=
"
test08
"
;
$post_data
[
'
submit
'
]
=
"
submit
"
;
$url
=
'
http://xxx.xxx.xxx.xx/xx/xxx/top.php
'
;
$o
=
""
;
foreach
(
$post_data
as
$k
=>
$v
)
{
$o
.=
"
$k
=
"
.
urlencode
(
$v
)
.
"
&
"
;
}
$post_data
=
substr
(
$o
,
0
,-
1
)
;
$ch
=
curl_init
()
;
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
)
;
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
)
;
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
)
;
//为了支持cookie
curl_setopt
(
$ch
,
CURLOPT_COOKIEJAR
,
'
cookie.txt
'
)
;
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$post_data
)
;
$result
=
curl_exec
(
$ch
)
;
2. 通过fsockopen
$URL
=‘
http
:
//xxx.xxx.xxx.xx/xx/xxx/top.php';
$post_data
[
'
clientname
'
]
=
"
test08
"
;
$post_data
[
'
clientpasswd
'
]
=
"
test08
"
;
$post_data
[
'
submit
'
]
=
"
ログイン
"
;
$referrer
=
""
;
// parsing the given URL
$URL_Info
=
parse_url
(
$URL
)
;
// Building referrer
if
(
$referrer
==
""
)
// if not given use this script as referrer
$referrer
=
$_SERVER
[
"
SCRIPT_URI
"
]
;
// making string from $data
foreach
(
$post_data
as
$key
=>
$value
)
$values
[]
=
"
$key
=
"
.
urlencode
(
$value
)
;
$data_stri
相关文档:
PHP获取时间错误的修正方法
今天运行PHP程序的时候,很奇怪,为什么PHP获取的时间比实际时间整整少了8小时,以前也没注意这个问题,总以为是时间显示错了,是安装软件的问题,今天在网上查了下资料,原来另有原因。
其实这和时区有关,PHP默认获取0时区开始的时间,中国在东八区,因此,我们中 ......
1.配置IIS下的PHP环境
我用的是Windows server 2003+IIS 6.0+PHP,但刚开始用的PHP5.3,按照网上的方法http://www.gzu521.com/campus/article/network/200902/182924.htm一步步配置,但是结果运行出现了一个问题,就是The FastCGI Handler was unable to process the request.找了很多解决方法但是还是没有解决,最后我换成 ......
basename: 返回不含路径的文件字符串。
chgrp: 改变文件所属的群组。
chmod: 改变文件的属性。
chown: 改变文件的拥有者。
clearstatcache: 清除文件状态快取。
copy: 复制文件。
delete: 无用的项目。
dirname: 取得路径中的目录名。
diskfreespace: 取得目录所在的剩余可用空间。
fclose: 关闭已打开的 ......
晚上特意花了个时间,自己动手试了下。
在项目中一直碰到Cookie跨域访问及SessionId跨域传递问题
范例:
index.php
<?php
include_once('a.php');
session_start();
$_SESSION['k'] = uniqid();
setcookie("sess", session_id(), time()+3600, "/", ".ipggg.com");
echo "index.php<br />\n";
echo $ ......