function sendSMS($uid,$pwd,$mobile,$content,$time='',$mid='')
{
('15821162098').'&content='.urlencode($content);
$URL = 'http://www.smsadmin.cn/..../'; //需要提交到的页面
//下面这段是要提交的数据
$post_data['uid'] = 'le***';
$post_data['pwd'] = '11111';
$post_data['mobile'] = '158211****';
$post_data['content'] ='您好';
$referrer="";
$URL_Info=parse_url($URL);
if($referrer=="")
{
$referrer=$_SERVER["SCRIPT_URI"];
}
foreach ($post_data as $key=>$value)
{
$values[]="$key=".urlencode($value);
}$data_string=implode("&",$values);//提交的数据格式是 a=1&b=2
// Find out which port is needed - if not given use standard (=80)
if (!isset($URL_Info["port"])) {
$URL_Info["port"]=80;
// building POST-request:
//一般做网站用form提交数据后,之后的操作就不用我们不管了,
//这里就是在模拟POST操作的HTTP头,具体的可以去查HTTP协议的资料,并不复杂
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referrer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";
//exit;
}
//fsockopen的用法就这样子了,不做多说明
$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);
fputs($fp, $request);//把HTTP头发送出去
while(!feof($fp)) {
//$result 是提交后返回的数据
$result .= fgets($fp, 1024);
}
fclose($fp);
//POST方式提交
if( trim($result) == '0发送成功!' )
{
return "发送成功!";
}
else
{
return "发送失败! 状态:".$result;
}
}
这是一个PHP通过post发送数据到另一个网站实现发送短信的功能,对方采用的是GBK的编码,我们是UTF8的编码,发送过去就出错,返回了一个乱码,前面带了一个5,这个5表示提交信息不全,不清楚哪里出了问题
{
('15821162098').'&content='.urlencode($content);
$URL = 'http://www.smsadmin.cn/..../'; //需要提交到的页面
//下面这段是要提交的数据
$post_data['uid'] = 'le***';
$post_data['pwd'] = '11111';
$post_data['mobile'] = '158211****';
$post_data['content'] ='您好';
$referrer="";
$URL_Info=parse_url($URL);
if($referrer=="")
{
$referrer=$_SERVER["SCRIPT_URI"];
}
foreach ($post_data as $key=>$value)
{
$values[]="$key=".urlencode($value);
}$data_string=implode("&",$values);//提交的数据格式是 a=1&b=2
// Find out which port is needed - if not given use standard (=80)
if (!isset($URL_Info["port"])) {
$URL_Info["port"]=80;
// building POST-request:
//一般做网站用form提交数据后,之后的操作就不用我们不管了,
//这里就是在模拟POST操作的HTTP头,具体的可以去查HTTP协议的资料,并不复杂
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referrer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";
//exit;
}
//fsockopen的用法就这样子了,不做多说明
$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);
fputs($fp, $request);//把HTTP头发送出去
while(!feof($fp)) {
//$result 是提交后返回的数据
$result .= fgets($fp, 1024);
}
fclose($fp);
//POST方式提交
if( trim($result) == '0发送成功!' )
{
return "发送成功!";
}
else
{
return "发送失败! 状态:".$result;
}
}
这是一个PHP通过post发送数据到另一个网站实现发送短信的功能,对方采用的是GBK的编码,我们是UTF8的编码,发送过去就出错,返回了一个乱码,前面带了一个5,这个5表示提交信息不全,不清楚哪里出了问题
function sendSMS($uid,$pwd,$mobile,$content,$time='',$mid='')
{
('15821162098').'&content='.urlencode($content);
$URL = 'http://www.smsadmin.cn/..../'; //需要提交到的页面
//下面这段是要提交的数据
$post_data['uid'] = 'le***';
$post_data['pwd'] = '11111';
$post_data['mobile'] = '158211****';
$post_data['content'] ='您好';
$referrer="";
$URL_Info=parse_url($URL);
if($referrer=="")
{
$referrer=$_SERVER["SCRIPT_URI"];
}
foreach ($post_data as $key=>$value)
{
$values[]="$key=".urlencode($value);
}$data_string=implode("&",$values);//提交的数据格式是 a=1&b=2
// Find out which port is needed - if not given use standard (=80)
if (!isset($URL_Info["port"])) {
$URL_Info["port"]=80;
// building POST-request:
//一般做网站用form提交数据后,之后的操作就不用我们不管了,
//这里就是在模拟POST操作的HTTP头,具体的可以去查HTTP协议的资料,并不复杂
$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";
$request.="Host: ".$URL_Info["host"]."\n";
$request.="Referer: $referrer\n";
$request.="Content-type: application/x-www-form-urlencoded\n";
$request.="Content-length: ".strlen($data_string)."\n";
$request.="Connection: close\n";
$request.="\n";
$request.=$data_string."\n";
//exit;
}
//fsockopen的用法就这样子了,不做多说明
$fp = fsockopen($URL_Info["host"], $URL_Info["port"]);
fputs($fp, $request);//把HTTP头发送出去
while(!feof($fp)) {
//$result 是提交后返回的数据
$result .= fgets($fp, 1024);
}
fclose($fp);
//POST方式提交
if( trim($result) == '0发送成功!' )
{
return "发送成功!";
}
else
{
return "发送失败! 状态:".$result;
}
}
这是一个PHP通过post发送数据到另一个网站实现发送短信的功能,对方采用的是GBK的编码,我们是UTF8的编码,发送过去就出错,返回了
字符串用urlencode
数组用json_encode
什么叫模拟POST提交数据函数?自己弄个表单 POST 一下 然后 $_POST 变量数组不就有了?