I would like to get the HTTP status code of a URL using PHP. I think CURL is the way to go but I can't see how to do it. I see I can use curl_getinfo on the CURL session after I've curl_exec'ed it but I can't see what options I should set to get CURL to only get the HTTP status code and not retrieve the data at the URL.
I'm not an expert on HTTP. Would I ever encounter a response where the code is not at the position of $data as in the above example? I just want to be sure that this method of delimiting the response code will always work for any response.
So I'm using a single entry point found in a previous question of mine: [URL] We all know what 404 errors is, so no explanation needed there. However, when using the single entry point index.php?page=pokemon, it doesn't go to the 404 page when trying to access a page that is non-existent. So how can I solve this problem which would make it more user friendly and direct the visitors to my 404 page so they won't see all the PHP errors?
Http Status Code 500 - Set_time_limit Throws A 500 Error?
When I use set_time_limit and the script runs for any amount of time greater than 360 seconds, it throws a 500 error.359, nothing, 360 and above, error.I don't have access to php.ini, how can I fix this bug?
Http Status Code Is Use To Tell The Client The Session Has Timed Out?
In a webpage, it uses YUI connection manager/datasource to send AJAX requests to the server, if the session (which contains the info on whether the user has been authenticated) has already timed out, those ajax responses that can only be viewed by authenticated users should return an http status code, telling the client that the session has already timed out, then the client either simply redirects him to the login page or asks him if he wants to extend the session.My question is that, in this situation, what http status code is the most appropriate to tell the client the session has timed out?
Http Status Code 404 - Image Link In Function 404's
I have a valid link that goes to a picture located on my web server. It is a simple jpg image, I can copy and paste this link into my web browser and it loads fine. The issue comes in when I try to call a few php functions on the image. such as getimagesize or fopen. they both return 404 errors even though the image is there. Does anyone know that could be causing this?
Fetch The Contents Of A Page No Matter What HTTP Status Code?
I'm currently using file_get_contents() to fetch the contents of a page which is sort of like an Authentication API. It works great for the default system which most people use (which just uses the default HTTP/1.1 200 status code), but some people send relevant HTTP status codes for different errors. For example 401 PASSWORD_FAIL, in which case it would set the HTTP status to 401 and output 'PASSWORD_FAIL' to the page, which is the part I want to get. But the 401 status code causes file_get_contents() to error out and not do anything. What is the simplest PHP function I can use to get the contents of the page and just ignore the HTTP status code?
Turn Off Default HTTP Status Code Errors In Zend Server?
Every time I return some status code in my PHP code, Zend Server gives me following error appended on the bottom of my website (with the message of HTTP code I returned). So for example, if I return 401, it gives me another 401 error appended to my 401 page:
Is there any way to turn it off? I use Zend Server Community Edition 5.0 with PHP 5.2.
It seems to be default Apache error handling. Is there a way to disable it? Preferably without having my own error pages.
I tried to edit my .htaccess with ErrorDocument directives. It still gives me my error page (blank page) + Apache error (like on screenshot above).
This isn't happening with ZendServer 4 I have on server. I use ZendServer 5 on localhost tho. Is it possible to be some kind of bug or misconfiguration from Zend side?
(In all test cases I return 401)
When I use default ZendServer configuration + ErrorDocument directives in .htaccess, I get my own error page + Apache error page appended bellow it.
When I use default ZendServer configuration + disable my own ErrorDocument directives, I get just Apache error page.
When I change Apache error pages to blank files + use my own ErrorDocument directives, I get the desired behavior, however errors 404 still append default Apache errors bellow my own.
Apache - Make Set HTTP Status Code To 500 Automatically In Case Of Any Error Condition?
I am running Apache 2.2.15 with PHP 5.3.2, 'display_errors' disabled, 'display_startup_errors' disabled, 'log_errors' enabled. At my setup (so I consider it a norm), PHP aborts on fatal errors, which is good, and sets HTTP status code to 500. Fatal errors include E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR and, probably, E_RECOVERABLE_ERROR (cannot trigger it myself, so can't easily check what happens). I think it is a good idea that it does set the code to 500, because I think it is the right thing to do - obviously if your script contains syntax errors and/or fails to do what is supposed to do at runtime, it is a server error, if we consider PHP part of the server.
Now, here is the important part: Anyway, I have now installed XDebug to track errors better, but I can see that now, no matter the error, even though the script aborts as before on fatal errors, the HTTP status code is always 200. This breaks my client that 'talks' to Apache/PHP via HTTP :|
Also, setting display_errors to On/1, makes PHP no longer set HTTP status code to 500 and exhibits exactly the same behavior as with XDebug above. I am very much dependent on reliable status code behavior here, and this all leads me to believe it's some kind of fluke or random like weather.. or am I missing something?[URL]..
For my part, I have disabled XDebug, seeing as it is what causes the bad behavior in the first place. I only used it for stack tracing anyway, and now use a custom error handler for that instead. Also, the linked article is from 2008, apparently PHP does set HTTP status code to 500 automatically these days. It does so here. Without XDebug, of course.
On High System Load - Status Code Is Safe To Return?
I am wondering how can I issue a HTTP Status code, that will cause crawlers to try later for that content, as the system currently is running on high load. Does a 304 status and no content display resolves this issue?
Send A Status Code In PHP Without Maintaining An Array Of Status Names?
All I want to do, is send a 404 status code from PHP - but in a generic fashion. Both Router::statusCode(404) and Router::statusCode(403) should work, as well as any other valid HTTP status code I do know, that you can specify a status code as third parameter to header. Sadly this only works if you specify a string. Thus calling header('', false, 404) does not work.Furthermore I know, that one can send a status code via a header call with a status line: header('HTTP/1.1 404 Not Found')But to do this I have to maintain an array of reason phrases (Not Found) for all status codes (404). I don't like the idea of this, as it somehow is a duplication of what PHP already does itself (for the third header parameter).So, my question is: Is there any simple and clean way to send a status code in PHP?
Http Status Code 500 - Files On The Server Generated 500 "Internal Server Error"
Everything was working fine till last morning (12 hours ago). But now each of PHP page is showing "500 Internal Server Error". Please look at this link http://abusadat.com. It's an WordPress site. I have thought it's about WordPress.
But I have a sub-domain, where there is a single PHP file - http://demo.abusadat.com/fb-apps/index.php, which gets same error. Though at the same location, there is a HTML file http://demo.abusadat.com/fb-apps/test.html, which works fine. To test if any syntax in PHP page causes that error, I have placed a "die('some message')" at the first line of that "index.php" file, but it shows same error. There is no HTAccess in that sub-domain.
Everything was working - suddenly all PHP stopped, I can't get the problem. Can anyone help?
Edited: *Latest Error log from cPanel*
[Mon Jun 27 14:42:30 2011] [error] [client 220.127.116.11] File does not exist: /home/abusadat/public_html/demo.abusadat/404.shtml [Mon Jun 27 14:42:30 2011] [error] [client 18.104.22.168] File does not exist: /home/abusadat/public_html/demo.abusadat/favicon.ico [Mon Jun 27 14:42:29 2011] [error] [client 22.214.171.124] File does not exist: /home/abusadat/public_html/demo.abusadat/404.shtml [Mon Jun 27 14:42:29 2011] [error] [client 126.96.36.199] File does not exist: /home/abusadat/public_html/demo.abusadat/favicon.ico [Mon Jun 27 14:42:26 2011] [error] [client 188.8.131.52] File does not exist: /home/abusadat/public_html/demo.abusadat/404.shtml
Fopen Failed "HTTP Request Failed", But Response Header Has A Status Code 200?
I have a PHP script, that should connect to a proxy, chosen from a proxy list and download a file. Some of the proxies (out of 200-400 working ones) work perfectly, but others don't, and I cannot find out why.Here the code that connects through the proxy:
Right now we've got web pages that show UI elements, and web pages that just process form submissions, and then redirect back to the UI pages. They do this using PHP's header() function:
This causes a 302 Found response to be sent; according to the HTTP 1.1 spec, 302 is for cases where "The requested resource resides temporarily under a different URI." [HTTP 1.1 spec]
Functionally, this is fine, but it doens't seem like this is the proper status code for what we're doing. It looks like 303 ("See Other") is the appropriate status here, so I'm wondering if there's any reason not to use it. We'd have to be more explicit in our use of header(), since we'd have to specify that status line rather than just a Location: field.