php get数据问题请教 既然是 post,那么怎么用 $_GET 接受呢?要用 $_POST ! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?php$oldip=$_POST["oldip"]; $newip=$_POST["newip"];$urldata=$_POST["urldata"];$agent=$_POST["agent"];$normal=$_POST["normal"];$error=$_POST["error"];file_put_contents(test.txt,$oldip,FILE_APPEND);file_put_contents(test.txt,$newip,FILE_APPEND);file_put_contents(test.txt,$urldata,FILE_APPEND);file_put_contents(test.txt,$agent,FILE_APPEND);file_put_contents(test.txt,$normal,FILE_APPEND);file_put_contents(test.txt,$error,FILE_APPEND);?>使用$_POST之后,oldip、newip、urldata、agent、normal、error变量的数据都收不到了,这是为什么呢?谢谢! 你把参数放到 url里面传递了,怎么能获取到数据呢!$_REQUEST$_POST$_GET都 记录下来,看看值在哪传的 嗯,你实际是 get 方式传值的因为有 spm=601#/按约定 # 表示锚点,不会传往 文本服务器所以其后的内容被截断了,所以你接收不到而用 post 传值时就不会出现这种情况贴出你的 curl 代码 明显你是用get方式传递的。get 传递的参数需要用urlencode转一次。http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http://detail.ju.taobao.com/home.htm?spm=601#/&agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) &normal=100&error=102应该改为echo 'http://218.204.14.50/test/?oldip='.urlencode('61.141.251.21').'&newip='.urlencode('61.141.251.25').'&urldata='.urlencode('http://detail.ju.taobao.com/home.htm?spm=601#/').'&agent='.urlencode('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) ').'&normal=100&error=102';http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http%3A%2F%2Fdetail.ju.taobao.com%2Fhome.htm%3Fspm%3D601%23%2F&agent=Mozilla%2F4.0+%28compatible%3B+MSIE+6.0%3B+Windows+NT+5.1%3B+SV1%3B+QQDownload+732%3B+.NET4.0C%3B+.NET4.0E%29+&normal=100&error=102 谢谢xuzuning、fdipzone版主的回复curl代码: CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { CString url("http://218.204.14.50/test/?oldip="); url += csoldip; url += "&newip="; url += csnewip; url += "&urldata="; url += csurldata; url += "&agent="; url += csagent; url += "&normal="; url += csnormal; url += "&error="; url += cserror; curl_easy_setopt(curl, CURLOPT_URL, CT2A(url)); curl_easy_setopt(curl, CURLOPT_HTTPGET); res = curl_easy_setopt(curl, CURLOPT_USERAGENT, "tian_test"); res = curl_easy_perform(curl); if(CURLE_OK == res) return TRUE; curl_easy_cleanup(curl); } curl_global_cleanup();客户端使用urlencode转码之后,后台是不是还要解码?谢谢! 你这是 C++ 还是 C#有对应于 php urlencode 的函数吗?如果有,则将 形如 url += csoldip; 的改为形如 url += urlencode(csoldip); 的url 编码后,php 端无需解码 urlencode之后还是获取不到agent、normal、error数据,但将urldata值置为test之后,就可以收到数据了,怀疑是不是$_GET长度有限制,如果不用$_GET、$_REQUEST,还有其它解决方案吗?谢谢! get 方式有 2k 的上限所以你这的该用 post 方式http://www.baidu.com/s?wd=c%2B%2B+curl+post&ie=utf-8 $_GET有2k的限制,改用POST就好了。 谢谢xuzuning 、fdipzone版主的回复,客户端改用POST之后,后台基本可以获取到数据了,但遇到了新的问题,再请教一下:PC客户端vc ++ crul post数据至后台:http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http://detail.ju.taobao.com/home.htm?uastk=8c3def7900&userid=301115#/&agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) &normal=100&error=102后台PHP代码:oldip=$_POST['oldip']; //结果:61.141.251.21newip=$_POST['newip']; //结果:61.141.251.25agent=$_POST['agent']; //结果:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)normal=$_POST['normal']; //结果:100error=$_POST['error']; //结果:102以上变量都能正确获取,但urldata获取有问题urldata=$$_POST['urldata']; //希望获取的内容:http://detail.ju.taobao.com/home.htm?uastk=8c3def7900&userid=301115#/但实际上获取的内容:http://detail.ju.taobao.com/home.htm?uastk=8c3def7900,无法获取&userid=301115#/,可能是&号分割的问题,请问这种情况应该怎么处理? 你 file_put_contents('test.txt', print_r($_POST,1));贴出 test.txt 的内容 使用urlencode已解决,再次感谢2位版主的帮助。谢谢! php网站收费问题 求linux下PHPunit 安装配置 paypal如何申请AIP测试用户 php东拉西扯的居然扯成了一门超过10年的语言 求删除和更新sql语句 php数据库插入数据问题,死活插不进去,求大神指导 做过工商银行B2C支付接口开发的朋友来帮帮看看 调查一下:大家都用什么模板?? 刚接触PHP,请问我用PHPED编辑的文件,如何运行呢?就是说如何在IE下看呢,我想看看效果。 ◆◆◆◆mysql中,select语句的一个问题? CentOS下在php中使用socket连接错误Permission denied 保存访问者微信头像至服务器
$oldip=$_POST["oldip"];
$newip=$_POST["newip"];
$urldata=$_POST["urldata"];
$agent=$_POST["agent"];
$normal=$_POST["normal"];
$error=$_POST["error"];
file_put_contents(test.txt,$oldip,FILE_APPEND);
file_put_contents(test.txt,$newip,FILE_APPEND);
file_put_contents(test.txt,$urldata,FILE_APPEND);
file_put_contents(test.txt,$agent,FILE_APPEND);
file_put_contents(test.txt,$normal,FILE_APPEND);
file_put_contents(test.txt,$error,FILE_APPEND);
?>使用$_POST之后,oldip、newip、urldata、agent、normal、error变量的数据都收不到了,这是为什么呢?
谢谢!
$_POST
$_GET
都 记录下来,看看值在哪传的
因为有 spm=601#/
按约定 # 表示锚点,不会传往 文本服务器
所以其后的内容被截断了,所以你接收不到而用 post 传值时就不会出现这种情况
贴出你的 curl 代码
http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http%3A%2F%2Fdetail.ju.taobao.com%2Fhome.htm%3Fspm%3D601%23%2F&agent=Mozilla%2F4.0+%28compatible%3B+MSIE+6.0%3B+Windows+NT+5.1%3B+SV1%3B+QQDownload+732%3B+.NET4.0C%3B+.NET4.0E%29+&normal=100&error=102
curl代码:
CURL *curl;
CURLcode res; curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
CString url("http://218.204.14.50/test/?oldip=");
url += csoldip;
url += "&newip=";
url += csnewip;
url += "&urldata=";
url += csurldata;
url += "&agent=";
url += csagent;
url += "&normal=";
url += csnormal;
url += "&error=";
url += cserror;
curl_easy_setopt(curl, CURLOPT_URL, CT2A(url));
curl_easy_setopt(curl, CURLOPT_HTTPGET);
res = curl_easy_setopt(curl, CURLOPT_USERAGENT, "tian_test");
res = curl_easy_perform(curl);
if(CURLE_OK == res)
return TRUE;
curl_easy_cleanup(curl);
}
curl_global_cleanup();客户端使用urlencode转码之后,后台是不是还要解码?
谢谢!
有对应于 php urlencode 的函数吗?
如果有,则将 形如 url += csoldip; 的
改为形如 url += urlencode(csoldip); 的
url 编码后,php 端无需解码
所以你这的该用 post 方式
http://www.baidu.com/s?wd=c%2B%2B+curl+post&ie=utf-8
$_GET有2k的限制,改用POST就好了。
PC客户端vc ++ crul post数据至后台:
http://218.204.14.50/test/?oldip=61.141.251.21&newip=61.141.251.25&urldata=http://detail.ju.taobao.com/home.htm?uastk=8c3def7900&userid=301115#/&agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E) &normal=100&error=102
后台PHP代码:
oldip=$_POST['oldip']; //结果:61.141.251.21
newip=$_POST['newip']; //结果:61.141.251.25
agent=$_POST['agent']; //结果:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)
normal=$_POST['normal']; //结果:100
error=$_POST['error']; //结果:102
以上变量都能正确获取,但urldata获取有问题
urldata=$$_POST['urldata']; //希望获取的内容:http://detail.ju.taobao.com/home.htm?uastk=8c3def7900&userid=301115#/
但实际上获取的内容:http://detail.ju.taobao.com/home.htm?uastk=8c3def7900,无法获取&userid=301115#/,可能是&号分割的问题,请问这种情况应该怎么处理?
file_put_contents('test.txt', print_r($_POST,1));
贴出 test.txt 的内容