In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to judge the status of php http, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!
Php's method to judge the state of http: [header ("HTTP/1.1 404 Not Found"); $url= "http://www.xxxx.com/preg.php"; $ch = curl_init (); curl_seto...].
This article operating environment: windows10 system, php 7, thinkpad T480 computer.
In the actual project development, we sometimes need to know whether the remote URL address can be accessed properly, and decide whether to proceed to the next step by judging whether it is normal or not. So how do we judge the status of HTTP? In fact, it is not difficult, we can take the following two ways, and then let's take a look at these two ways.
File preg.php
Header ("HTTP/1.1 404 Not Found")
The first method:
$url = "http://www.demo.com/preg.php";$ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HEADER, TRUE); curl_setopt ($ch, CURLOPT_NOBODY, TRUE); / / remove bodycurl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE); $head = curl_exec ($ch); $httpCode = curl_getinfo ($ch, CURLINFO_HTTP_CODE); echo $httpCode;curl_close ($ch)
Running result:
four hundred and four
The second method:
Echo'; print_r (get_headers ("http://www.demo.com/preg.php",1));
Running result:
Array ([0] = > HTTP/1.1 404 Not Found [Date] = > Fri, 28 Sep 2018 09:27:03 GMT [Server] = > Apache/2.4.23 (Win32) OpenSSL/1.0.2j PHP/5.5.38 [X-Powered-By] = > PHP/5.5.38 [Content-Length] = > 0 [Content-Type] = > text/html) these are all the contents of the article "how php judges http status". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.