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
相关文档:
test.php -------------------------------------------------------------------------------------
echo $_SERVER['DOCUMENT_ROOT'].""; //获得服务器文档根
echo $_SERVER['PHP_SELF'].""; //获得执行该代码的文件服务器绝对路径
/*
php手册上的解释: “PHP_SELF” 当前正在执行脚本的文件名,与 docum ......
优秀的PHP代码应该是结构化的。大段的代码应该被分割整理成一个个函数或方法,而那些不起眼的小段代码则应该加上注释,以便日后清楚它们的用途。
而且应该尽可能地把前台代码如HTML、CSS、Javascript等从程序中分离出来。PHP的面向对象编程特性可以很好地帮助程序员将代码整理有
序。
&n ......
晚上特意花了个时间,自己动手试了下。
在项目中一直碰到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 $ ......
开源建站程序让编程高手和只懂打字上网的人都可以快速建立一个功能强大、界面漂亮的网站。不管你是想建一个博客、论坛、CMS、电子商务网站,或是Wiki、相册管理、RSS聚合和类Digg网站。你都可以通过这些建站工具快速建立。
我们之前介绍过23个开源的CMS管理系统,现在则让我们来看一下26款开源建站程序。
......
<?php
$n = array('13','14','55','10','54','2','79','106','89','90','22','60','111','77777','-110','-10','123');
function partition($n,$left,$right)
{
global $n;
$pivot = $n[$left];
$lo=$left;
$hi=$right+1;
while($lo+1!=$hi) {
if($n[$lo+1]<$pivot)
$lo++;
else if($n[$hi-1] ......