Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial php get数据问题请教

php get数据问题请教

Jun 23, 2016 pm 01:47 PM

PC客户端通过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?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

后台PHP获取数据代码:
$oldip=$_GET["oldip"]; 
$newip=$_GET["newip"];
$urldata=$_GET["urldata"];
$agent=$_GET["agent"];
$normal=$_GET["normal"];
$error=$_GET["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);
?>

后台只能获取到oldip、newip、urldata数据,获取不到agent、normal、error数据,请问高手可能是什么原因?如何解决?
非常感谢!


回复讨论(解决方案)

既然是 post,那么怎么用 $_GET 接受呢?
要用 $_POST !

$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';
Copy after login


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 端无需解码

哦,忘了写,客户端是C++,我试试。多谢!

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

urlencode之后还是获取不到agent、normal、error数据,但将urldata值置为test之后,就可以收到数据了,怀疑是不是$_GET长度有限制,如果不用$_GET、$_REQUEST,还有其它解决方案吗?谢谢!



$_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.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 的内容

使用urlencode已解决,再次感谢2位版主的帮助。谢谢!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles