首頁 >後端開發 >php教程 >速戰速決 6 - PHP: 取得 http 請求資料, 取得 get 資料 與 post 資料, json 字串與物件之間的相互轉換

速戰速決 6 - PHP: 取得 http 請求資料, 取得 get 資料 與 post 資料, json 字串與物件之間的相互轉換

WBOY
WBOY原創
2016-07-29 08:50:581043瀏覽

[源碼下載]

速戰速決(6) - PHP: 取得http 請求資料, 取得get 資料與post 資料, json 字串與物件之間的相互轉換


作者:webabcd
介紹
速決戰速決之PHP

  • 取得http 請求資料
  • 取得get 資料與post 資料
  • json 字串與物件之間的相互轉換




2、取得get 資料與post 資料

http/http2.php

<?<span>php
</span><span>/*</span><span>*
 * 获取 http 请求数据
 </span><span>*/</span><span>//</span><span> 通过 $_SERVER 获取相关数据</span><span>echo</span> "PHP_SELF : " . <span>$_SERVER</span>['PHP_SELF'] . "<br />"<span>;
</span><span>echo</span> "GATEWAY_INTERFACE : " . <span>$_SERVER</span>['GATEWAY_INTERFACE'] . "<br />"<span>;
</span><span>echo</span> "SERVER_ADDR : " . <span>$_SERVER</span>['SERVER_ADDR'] . "<br />"<span>;
</span><span>echo</span> "SERVER_NAME : " . <span>$_SERVER</span>['SERVER_NAME'] . "<br />"<span>;
</span><span>echo</span> "SERVER_SOFTWARE : " . <span>$_SERVER</span>['SERVER_SOFTWARE'] . "<br />"<span>;
</span><span>echo</span> "SERVER_PROTOCOL : " . <span>$_SERVER</span>['SERVER_PROTOCOL'] . "<br />"<span>;
</span><span>echo</span> "REQUEST_METHOD : " . <span>$_SERVER</span>['REQUEST_METHOD'] . "<br />"<span>;
</span><span>echo</span> "REQUEST_TIME : " . <span>$_SERVER</span>['REQUEST_TIME'] . "<br />"<span>;
</span><span>echo</span> "REQUEST_TIME_FLOAT : " . <span>$_SERVER</span>['REQUEST_TIME_FLOAT'] . "<br />"<span>;
</span><span>echo</span> "QUERY_STRING : " . <span>htmlspecialchars</span>(<span>$_SERVER</span>['QUERY_STRING']) . "<br />"<span>;
</span><span>echo</span> "DOCUMENT_ROOT : " . <span>$_SERVER</span>['DOCUMENT_ROOT'] . "<br />"<span>;
</span><span>echo</span> "HTTP_ACCEPT : " . <span>$_SERVER</span>['HTTP_ACCEPT'] . "<br />"<span>;
</span><span>echo</span> "HTTP_ACCEPT_CHARSET : " . <span>$_SERVER</span>['HTTP_ACCEPT_CHARSET'] . "<br />"<span>;
</span><span>echo</span> "HTTP_ACCEPT_ENCODING : " . <span>$_SERVER</span>['HTTP_ACCEPT_ENCODING'] . "<br />"<span>;
</span><span>echo</span> "HTTP_ACCEPT_LANGUAGE : " . <span>$_SERVER</span>['HTTP_ACCEPT_LANGUAGE'] . "<br />"<span>;
</span><span>echo</span> "HTTP_CONNECTION : " . <span>$_SERVER</span>['HTTP_CONNECTION'] . "<br />"<span>;
</span><span>echo</span> "HTTP_HOST : " . <span>$_SERVER</span>['HTTP_HOST'] . "<br />"<span>;
</span><span>echo</span> "HTTP_REFERER : " . <span>$_SERVER</span>['HTTP_REFERER'] . "<br />"<span>;
</span><span>echo</span> "HTTP_USER_AGENT : " . <span>$_SERVER</span>['HTTP_USER_AGENT'] . "<br />"<span>;
</span><span>echo</span> "HTTPS : " . <span>$_SERVER</span>['HTTPS'] . "<br />"<span>;
</span><span>echo</span> "REMOTE_ADDR : " . <span>$_SERVER</span>['REMOTE_ADDR'] . "<br />"<span>;
</span><span>echo</span> "REMOTE_HOST : " . <span>$_SERVER</span>['REMOTE_HOST'] . "<br />"<span>;
</span><span>echo</span> "REMOTE_PORT : " . <span>$_SERVER</span>['REMOTE_PORT'] . "<br />"<span>;
</span><span>echo</span> "REMOTE_USER : " . <span>$_SERVER</span>['REMOTE_USER'] . "<br />"<span>;
</span><span>echo</span> "REDIRECT_REMOTE_USER : " . <span>$_SERVER</span>['REDIRECT_REMOTE_USER'] . "<br />"<span>;
</span><span>echo</span> "SCRIPT_FILENAME : " . <span>$_SERVER</span>['SCRIPT_FILENAME'] . "<br />"<span>;
</span><span>echo</span> "SERVER_ADMIN : " . <span>$_SERVER</span>['SERVER_ADMIN'] . "<br />"<span>;
</span><span>echo</span> "SERVER_PORT : " . <span>$_SERVER</span>['SERVER_PORT'] . "<br />"<span>;
</span><span>echo</span> "SERVER_SIGNATURE : " . <span>$_SERVER</span>['SERVER_SIGNATURE'] . "<br />"<span>;
</span><span>echo</span> "PATH_TRANSLATED : " . <span>$_SERVER</span>['PATH_TRANSLATED'] . "<br />"<span>;
</span><span>echo</span> "SCRIPT_NAME : " . <span>$_SERVER</span>['SCRIPT_NAME'] . "<br />"<span>;
</span><span>echo</span> "REQUEST_URI : " . <span>htmlspecialchars</span>(<span>$_SERVER</span>['REQUEST_URI']) . "<br />"<span>;
</span><span>echo</span> "PHP_AUTH_DIGEST : " . <span>$_SERVER</span>['PHP_AUTH_DIGEST'] . "<br />"<span>;
</span><span>echo</span> "PHP_AUTH_USER : " . <span>$_SERVER</span>['PHP_AUTH_USER'] . "<br />"<span>;
</span><span>echo</span> "PHP_AUTH_PW : " . <span>$_SERVER</span>['PHP_AUTH_PW'] . "<br />"<span>;
</span><span>echo</span> "AUTH_TYPE : " . <span>$_SERVER</span>['AUTH_TYPE'] . "<br />"<span>;
</span><span>echo</span> "PATH_INFO : " . <span>$_SERVER</span>['PATH_INFO'] . "<br />"<span>;
</span><span>echo</span> "ORIG_PATH_INFO : " . <span>$_SERVER</span>['ORIG_PATH_INFO'] . "<br />";


3、取得get 資料與post 資料

encode/json.phpre

以上就介紹了速戰速決6 - PHP: 取得http 請求資料, 取得get 資料與post 資料, json 字串與物件之間的相互轉換,包括了方面的內容,希望對PHP教學有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn