Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 关于PHP开发HTTP服务器

关于PHP开发HTTP服务器

Jun 23, 2016 pm 02:00 PM

最近因工作需要,要为一款手机游戏弄个管理游戏排行榜的服务器,经过同学介绍,认为使用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等等等方式的请求,能够测试你服务器是否能收到客户端的请求。


回复讨论(解决方案)

lz想表达什么意思。

不管怎么样都要赞一个,希望以后会有更多自己的心得分享给大家

感觉每个帖子都能帮助到我,楼主的经验非常好

楼主这是对自己学习的总结吗?

用$_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标准的数据类型

我还以为LZ是要用PHP开发一个类似Apache的Web服务器呢,原来。。。。

我觉得这应该是软文推广。。。看到最后一行秒懂。。好吧,我想多了。

lz想表达什么意思。 我只是分享一下我自己遇到的问题而已 或许能帮到跟我一样临时需要的人咯……

楼主这是对自己学习的总结吗?   可以算吧,不过我做完这服务器 以后或许也不会使用php呢 毕竟是临时需要而已嘛……

用$_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

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

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from 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

See all articles