Home Backend Development PHP Tutorial 关于PHP开发HTTP服务器解决办法

关于PHP开发HTTP服务器解决办法

Jun 13, 2016 am 11:52 AM
data get http nbsp post

关于PHP开发HTTP服务器
最近因工作需要,要为一款手机游戏弄个管理游戏排行榜的服务器,经过同学介绍,认为使用php来开发比较简单,所以就临时去学了php的基础语法和网上查了很多关于如何开发服务器的资料。
在这里本人谈谈我自己做服务器过程中遇到的问题,希望跟我一样临时需要开发php服务器的新手可以获得帮助,至于高手,你就无视我吧。
网上找的很多资料都是讲php如何模拟发送http请求的,很少有关于服务器如何获取客户端请求的资料,或许经过系统学习的都知道了,但是对于本人这种临时学习的,还真是个硬伤。
经过我查找的资料 php做的服务器接受客户端的数据可以通过$_POST,$_GET,$_REQUEST来获取。 客户端需要用对应的$_post,$_get 来提交数据,$_REQUEST似乎都可以。
至于$_POST,$_GET的区别,百度上太多了 你可以自己找找
$_POST,$_GET返回的就是你客户端传过来的参数,你可以通过处理这些参数来完成功能,至于你想返回数据给客户端,只需要echo就行了 
如果客户端使用get方式发送的请求,想获取数据很简单,只需要使用$_SERVER['QUERY_STRING'] 即可获取,信息来源于http://hi.baidu.com/iigyphfsjfgjkye/item/f180b2fbc5aa18ee1b111fc1 更多信息自己查看吧

我这次做的php服务器,不知道是什么原因,用$_POST,$_GET,$_REQUEST不能获取到数据。 所以找了$GLOBALS[$HTTP_RAW_POST_DATA]和file_get_contents("http://input")来获取数据
上面两个方式都能获取客户端post过来的请求 第一个听说似乎不能收一种数据,忘了  
我使用的是第二个 $request = file_get_contents("http://input") 就得到了客户端post过来的参数了。

在这里介绍一种软件Fidder,百度即能下载。这软件能代替客户端来发送get,post等等等方式的请求,能够测试你服务器是否能收到客户端的请求。

------解决方案--------------------
用$_POST,$_GET,$_REQUEST不能获取到数据。 所以找了$GLOBALS[$HTTP_RAW_POST_DATA]和file_get_contents("http://input")来获取数据。

你的数据是二进制流吗?

$_POST:通过 HTTP POST 方法传递的变量组成的数组。是自动全局变量。
$GLOBALS['HTTP_RAW_POST_DATA'] :总是产生 $HTTP_RAW_POST_DATA 变量包含有原始的 POST 数据。此变量仅在碰到未识别 MIME 类型的数据时产生。$HTTP_RAW_POST_DATA 对于 enctype="multipart/form-data" 表单数据不可用。
也就是说基本上$GLOBALS['HTTP_RAW_POST_DATA'] 和 $_POST是一样的。

但是如果post过来的数据不是PHP能够识别的,你可以用 $GLOBALS['HTTP_RAW_POST_DATA']来接收,比如 text/xml 或者 soap 等等。
 
补充说明:PHP默认识别的数据类型是application/x-www.form-urlencoded标准的数据类型

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

In iOS 17, Apple introduced several new privacy and security features to its mobile operating system, one of which is the ability to require two-step authentication for private browsing tabs in Safari. Here's how it works and how to turn it off. On an iPhone or iPad running iOS 17 or iPadOS 17, Apple's browser now requires Face ID/Touch ID authentication or a passcode if you have any Private Browsing tab open in Safari and then exit the session or app to access them again. In other words, if someone gets their hands on your iPhone or iPad while it's unlocked, they still won't be able to view your privacy without knowing your passcode

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

The famous activation script MAS2.2 version supports digital activation again. The method originated from @asdcorp and the team. The MAS author calls it HWID2. Download gatherosstate.exe (not original, modified) from https://github.com/massgravel/Microsoft-Activation-Scripts, run it with parameters, and generate GenuineTicket.xml. First take a look at the original method: gatherosstate.exePfn=xxxxxxx;DownlevelGenuineState=1 and then compare with the latest method: gatheros

How to automate tasks using PowerShell How to automate tasks using PowerShell Feb 20, 2024 pm 01:51 PM

If you are an IT administrator or technology expert, you must be aware of the importance of automation. Especially for Windows users, Microsoft PowerShell is one of the best automation tools. Microsoft offers a variety of tools for your automation needs, without the need to install third-party applications. This guide will detail how to leverage PowerShell to automate tasks. What is a PowerShell script? If you have experience using PowerShell, you may have used commands to configure your operating system. A script is a collection of these commands in a .ps1 file. .ps1 files contain scripts executed by PowerShell, such as basic Get-Help

Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

HTTP 200 OK: Understand the meaning and purpose of a successful response HTTP 200 OK: Understand the meaning and purpose of a successful response Dec 26, 2023 am 10:25 AM

HTTP Status Code 200: Explore the Meaning and Purpose of Successful Responses HTTP status codes are numeric codes used to indicate the status of a server's response. Among them, status code 200 indicates that the request has been successfully processed by the server. This article will explore the specific meaning and use of HTTP status code 200. First, let us understand the classification of HTTP status codes. Status codes are divided into five categories, namely 1xx, 2xx, 3xx, 4xx and 5xx. Among them, 2xx indicates a successful response. And 200 is the most common status code in 2xx

http request 415 error solution http request 415 error solution Nov 14, 2023 am 10:49 AM

Solution: 1. Check the Content-Type in the request header; 2. Check the data format in the request body; 3. Use the appropriate encoding format; 4. Use the appropriate request method; 5. Check the server-side support.

How to cancel your Apple subscription How to cancel your Apple subscription Oct 31, 2023 pm 11:13 PM

You can easily cancel AppleOne (like AppleOne) subscriptions, as well as third-party AppStore subscriptions, on your iPhone, iPad, or Mac. Apple offers a variety of services that Apple device owners can subscribe to, including AppleMusic, AppleTV+, AppleArcade, iCloud+, AppleNews+, and AppleFitness+. It also offers these services as a bundled subscription called Apple One. Apple in March 2023 made significant price increases for several of its services, including Apple TV+, Apple Arcade and

See all articles