Return HTTP Status Code

Apr 15, 2007

I guess if it is possible to obtain a HTTP response code (200 or 404) without fopening entire remote page.

www.example.com/a.php --> 200 THEN fopen()
www.example.com/b.php --> 404 THEN die()

I so would like to low overhead of server.

ADVERTISEMENT

Return A Specific Http Status Code

Aug 4, 2010

Is there a way to have a php script return a specific http status code rather than relying on apache to do it?

View 2 Replies View Related

Get HTTP Status Code

Jan 11, 2006

I know how to retrieve text from elements like the title on a web page using PHP but how do I get the status code returned in the header and assign it to a variable?

View 4 Replies View Related

Using CURL Get HTTP Status Code Of A URL

Jul 17, 2005

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.

View 2 Replies View Related

Parsing HTTP Status Code?

Sep 18, 2009

I am using PHP to parse the numeric portion of the HTTP status code response. Given a standard "HTTP/1.1 200 OK" response, I'd use:

$data = explode(' ', "HTTP/1.1 200 OK");
$code = $data[1];

I'm not an expert on HTTP. Would I ever encounter a response where the code is not at the position of $data[1] 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.

View 4 Replies View Related

Http Status Code 404 - Related To 404

Jan 5, 2010

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?

View 4 Replies View Related

Get The HTTP Status Code For A Remote Domain?

Nov 7, 2008

I would like to create a batch script, to go through 20,000 links in a DB, and weed out all the 404s and such. How would I get the HTTP status code for a remote url?

Preferably not using curl, since I dont have it installed.

View 5 Replies View Related

Http Status Code 500 - Set_time_limit Throws A 500 Error?

Mar 27, 2011

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?

View 2 Replies View Related

Http Status Code Is Use To Tell The Client The Session Has Timed Out?

Oct 31, 2009

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?

View 4 Replies View Related

Http Status Code 301 - 301 Redirect Error From Variable?

Apr 22, 2011

I am writing a 301 redirect, but getting an error when I pass the url through a variableI use this script to get the current page URL and Domain name.

<?php
$mainurl = "http://" .$_SERVER["SERVER_NAME"];
$pagename1 = "".$_SERVER["QUERY_STRING"];
?>

If the page does not redirect I use this to redirect the page.

<?php if ($row_rs_page['g_page_url'] != $pagename1)
$pagenameexists = "<p>page exists</p>";
[code]....

View 1 Replies View Related

Http Status Code 404 - Image Link In Function 404's

Apr 19, 2010

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?

View 3 Replies View Related

Http Status Code 404 Direct Access To Page?

Jun 25, 2009

Users to be able to access directly.

Code:function prevent_direct_access()
{
if($_SERVER['REQUEST_URI'] == $_SERVER['PHP_SELF'])
{

[code]...

The URL does not change but the content does.Need to add to tell search engines that this is a 404 and not to index it.The URL to change though.

View 5 Replies View Related

Getting HTTP Status Code From Multiple URLs Using Curl_multi?

Jan 8, 2011

Alright, so I'm using curl_multi_* to connect to various sites simultaneously. How would I return the HTTP Status Code to a variable for comparison?

View 1 Replies View Related

CURL Always Return Status Code?

Apr 1, 2011

i have write code cURL with php but it's always return status code, '0' or '1' i want to get data json with my cURL i have set cURL opt 'CURLOPT_RETURNTRANSFER' to 1 but still get status code..

this my code

<?php
function fetch_page($url)
{
$ch = curl_init();
$array = array(

[Code]...

View 4 Replies View Related

Fetch The Contents Of A Page No Matter What HTTP Status Code?

Aug 13, 2010

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?

View 1 Replies View Related

Correct HTTP Status Code To Send When A Site Is Down For Maintenance?

May 7, 2010

Is there a HTTP status code to tell Google (and others) to go away, index me again later? Basically, one that semantically tells clients that the site is down for maintenance?

The ones I have considered are

304 => Not modified
307 => Temporary redirect
410 => Gone
503 => Service Unavailable

I'm leaning towards the last one, but was just curious as to which one was proper choice.

Is this the correct way to send it with PHP?

header('Status: 503 Service Unavailable');

View 4 Replies View Related

Return Specific Status Code (for Example 24) In Symfony

Dec 9, 2010

i need to return crazy http code statuses for API in symfony

i need to return status code 24 i try to do it with:

$this->getResponse()->setStatusCode('24');

but i'm always getting response code 500

when i try to return "normal" status code like 404, 403:

$this->getResponse()->setStatusCode('403');

View 3 Replies View Related

Turn Off Default HTTP Status Code Errors In Zend Server?

Mar 17, 2010

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.

EDIT:

It seems to be default Apache error handling. Is there a way to disable it? Preferably without having my own error pages.

ADDITIONAL EDIT:

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?

BEHAVIOUR:

(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.

View 3 Replies View Related

Apache - Make Set HTTP Status Code To 500 Automatically In Case Of Any Error Condition?

Jun 19, 2010

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.

View 1 Replies View Related

On High System Load - Status Code Is Safe To Return?

Mar 4, 2011

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?

View 3 Replies View Related

HTTP Return Code: 405

Feb 24, 2003

I'm trying to add a child node to my XML file with following PHP-script: PHP Code:

View 2 Replies View Related

Send A Status Code In PHP Without Maintaining An Array Of Status Names?

Jan 25, 2011

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?

View 4 Replies View Related

Http Status Code 500 - Files On The Server Generated 500 "Internal Server Error"

Jun 27, 2011

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 59.93.241.43] File does not exist: /home/abusadat/public_html/demo.abusadat/404.shtml
[Mon Jun 27 14:42:30 2011] [error] [client 59.93.241.43] File does not exist: /home/abusadat/public_html/demo.abusadat/favicon.ico
[Mon Jun 27 14:42:29 2011] [error] [client 59.93.241.43] File does not exist: /home/abusadat/public_html/demo.abusadat/404.shtml
[Mon Jun 27 14:42:29 2011] [error] [client 59.93.241.43] File does not exist: /home/abusadat/public_html/demo.abusadat/favicon.ico
[Mon Jun 27 14:42:26 2011] [error] [client 59.93.241.43] File does not exist: /home/abusadat/public_html/demo.abusadat/404.shtml

View 1 Replies View Related

Fopen Failed "HTTP Request Failed", But Response Header Has A Status Code 200?

Jan 16, 2011

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:

$proxy = determine_proxy ($proxyList);
$proxyString = 'tcp://' . $proxy['ip'] . ':' . $proxy['port'];
$userAgent = $userAgents [rand (0, $agentsCount - 1)];

[code]...

View 2 Replies View Related

HTTP Status For Functional Redirect?

Nov 7, 2008

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:

header("Location: /other_page.php");

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.

View 3 Replies View Related

Use Self Defined Http Status Codes?

Jul 26, 2010

so http status codes are

1xx, 2xx, 3xx, 4xx, 5xx.

Could we self define http status codes such as 9xx for our own usage?

I didn't see too many people use self defined http status codes. I prefer not to use self defined http status codes. But I have no authentic reasons against it.

Here is one which use self defined http status codes.

[URL]

The advantage for that is we only need to check the header response and no need to check the body.

View 3 Replies View Related

Getting HTTP Status Codes For Web Pages Through Proxy

Apr 19, 2006

I'm having a terrible time trying to get HTTP status codes from web pages (404, 200, 301, etc.). I think a big part of the problem is that we're behind a proxy.

How would I modify the following code examples to connect through a proxy in order to get the status code?

function http_file_status($url, $followRedirects = true)
{
$url_parsed = parse_url($url);
if (!@$url_parsed['scheme']) $url_parsed = parse_url('http://'.$url);
extract($url_parsed);
if(!@$port) $port = 80;
if(!@$path) $path = '/'
if(@$query) $path .= '?'.$query;
$out = "HEAD $path HTTP/1.1";
$out .= "Host: $host";
$out .= "Connection: Close";
if(!$fp = @fsockopen($host, $port, $es, $en, 5)){
return false;
}
fwrite($fp, $out);
while (!feof($fp)) {
$s = fgets($fp, 128);
if(($followRedirects) && (preg_match('/^Location:/i', $s) != false)){
fclose($fp);
return http_file_status(trim(preg_replace("/Location:/i", "", $s)));
}
if(preg_match('@HTTP[/]1[.][01x][s]{1,}([1-5][01][0-9])[s].*$@', $s, $matches))
{
$status = $matches[1];
}
}
fclose($fp);
if(!empty($status))
{
return $status;
}
return false;
}

OR:

set_time_limit(20);
ob_start();
header("Content-Type: text/plain");
$host = "www.webmasterworld.com";
$port = 80;

$post = "HEAD / HTTP/1.1";
$post .= "Host: www.webmasterworld.com";
$post .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.2) Gecko/20060308 Firefox/1.5.0.2";
$post .= "Keep-Alive: 200";
$post .= "Connection: keep-alive";
$sock = fsockopen($host, $port, $errno, $errstr, 20.0);
fwrite($sock, $post, strlen($post));

while (!feof($sock)){
echo fgets($sock);
}
ob_end_flush();

View 1 Replies View Related

Remotely Checking HTTP Status With CURL?

Jun 6, 2011

I am trying to generate rows based on the code below. Would someone be able to tell me what I am doing wrong? I can't get the error reporting to work where I am. Are you able to use cURL within while loops?

while ($row = mysql_fetch_array($result_entries))
if ($row['active'] == "y") {
$ch = curl_init($row['url']);

[code]...

View 2 Replies View Related

Update Facebook Status By Http Request?

Apr 9, 2010

I try to send http request like: "POST [URL] but I receive nothing... in twitter I success: "POST [URL]"' I must use it in this way ,because of GFW...

View 1 Replies View Related

Parsing HTTP Status Codes For Interacting With API?

Oct 13, 2010

I'm building a script in PHP to interact with an API and need to be able to parse the HTTP status code the API is giving me. For the most part, it gives one of the following responses:

HTTP/1.1 401 Unauthorized
HTTP/1.1 403 Forbidden
HTTP/1.1 404 Not Found
HTTP/1.1 410 Gone

I need to be able to recognize which response is being given, and, if its 401 or 410, to keep going, but, if it's 401 or 403, to keep track and to shut down the script after a few in a row (because I've exceeded my call limit for the day). My code is pretty simple:

for($i = $start;$i < $end;$i++)
{
// construct the API url
$url = $base_url.$i.$end_url;

[code]....

My problem is I don't know what to put in the 'else' loop. I'm using the CodeIgniter framework, if anyone knows of any shortcuts to use. Also, I'm open to using cURL, but never have before.

View 2 Replies View Related

Reading Header HTTP Status Information From URL's

Jun 15, 2007

I have a MySQL Database which has a URL field.It has roughly 5000 records.
My Goal is to read all the URL's and print their HTTP Status Code (Like if its 200 OK or 404 etc)Information to the Screen. Now i did this using the CURL below CURL FUNCTIONS. Code:

View 3 Replies View Related

Fetch HTTP Response Header/redirect Status?

Aug 31, 2009

I am currently working on a PHP-based Tool to monitor a rather large number of URLs and their redirect status. I have spent quite some time on finding the best way to fetch the content of the HTTP response headers to extract the current redirect code and location. This is how it's done at the moment:

$resource = fopen( $url, 'r' );
$metadata = stream_get_meta_data( $resource );
$metadata = $metadata['wrapper_data'];
// Looping through the array to find the necessary fields

This works on 95% of the URLs I'm monitoring. For a few more I have solved it by parsing the actual HTML the website returns before the redirect is executed since it contained something like "This website has been moved here". This does not seem to be a very robust solution, but it helped in a few cases. This still leaves me with a number of URLs I can not check automatically. Tools like Ask Apache HTTP Headers Tool seem to be more reliable and I was wondering what could be a better way to obtain the redirect information?

View 1 Replies View Related

Web Services - Difference In Sending HTTP Status Codes ?

Oct 27, 2010

what is the difference from setting the responce status in php header("HTTP/1.0 404 Not Found");andheader("Status: 404 Not Found");What is the difference from the client point of view (aka browser or a client implementation for RESTful WS). I understood that the second one has to do something with CGI.

View 1 Replies View Related

Unix - System() - Return Status Is Always 0

Nov 9, 2010

I need to get the following scripts running.

// File: script_a.php
<?php exit(1); ?>
// File: script_b.php
<?php
system('php script_a.php', $return);
var_dump($return);
?>

Now my problem: On my windows system running script_b.php shows int(1) as expected. On our Unix-Server I always get int(0), what makes it impossible for me to check, if a certain failure happens inside the script_a.php.

View 14 Replies View Related

Use Cacti To Monitor HTTP Status Codes Of Request Responses?

Apr 27, 2009

I have a proxy script that makes HTTP GET requests to other pages using cURL through PHP. Is it possible to monitor what response codes are returned to those cURL requests, using Cacti? If not Cacti, possible with any similar monitoring system? For example, I want a report that shows how many responses came in each status category, ie, with a 200, a 404, 500, etc.

View 1 Replies View Related

Using Exec Function To Get A .exe Return Status Gives CGI Error

Aug 23, 2007

I'm trying to make a web page to work. It worked before so it has to
be something related with the configuration.
My problem is a call to a compiled executable (made for me) that
returns 1 or 0. It does not print any text to the standard ouput so
the error is strange:
CGI Error: The script can .. because of the HTTP headers (I have it in
spanish so the message is not the exact one).

As supposed, the HTTP headers are needed only if the executable prints
out a text to the browser but it's not the case. And (I repeat) It
worked as it before. The machine had to be formatted and the guy in
charge of that is not with me anymore.

View 5 Replies View Related

Return A 200 Ok Status Programmatically To Ajax Request?

Jan 21, 2010

I ask this question for the comment of this answer: url

EDIT

I missed an important point,should also keep the connection not closed.

I'm trying to figure out how long polling actually works.

View 1 Replies View Related

Stop Execution At The Middle Of Script That Return Success Status?

May 27, 2011

I am running the following php script via web browser:

<?php
require_once("test.php");
....
exit(0);
....
require_once("test2.php");
....
?>

I am debugging my php script. I want the script to stop execute some where at the line of "exit(0)". However, the php doesn't execute successfully. If I remove "exit(0)" then it works.How may I stop the PHP script execution in the middle?

View 1 Replies View Related

Exec - Return_var Codes And Return Status Of The Executed Command?

Feb 9, 2010

[URL]...

Code:<?
print "<br>executing 'hello':<br><b>";
exec ("hello", $output, $result);
var_dump($output);

[code]...

If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.does not have a list of output.

View 4 Replies View Related

Query To Return Values Where Person='$username' And Status=0 From One Table

Jun 25, 2011

I want my query to return the values where person='$username' and status=0 from one table, and the same in another table. Here's what I got:

Code: [Select]$GetStatus = "SELECT comments.status, friends.status FROM comments, friends WHERE (comments.person='$username' AND comments.status='0') OR (friends.user2='$username' AND friends.status='0')";

However it just returns values from different rows where the status is different than 0..

View 4 Replies View Related

Set Response Status Code?

May 28, 2011

I have an API call for which I need to be able to run some checks and potentially return various status codes. I don't need custom views or anything, I just need to return the proper code. If the user hasn't passed proper credentials, I need to return a 401 status. If they haven't sent a supported request format, I need to return a 400 status.

Because it's an API, all I really want to do is set the response status and exit with a simple, stupid message about why the request failed (probably using a exit). Just enough to get the job done, but I haven't been able to get this to work right. I've tried using PHP's header() and Cake's $this->header() (this is all in the controller), but although I get the exit message, the header shows a 200 OK status.

Using the code below, I get the message, but the header isn't set. What am I missing?

if( !$this->auth_api() ) {
header( '401 Not Authorized' );
exit( 'Not authorized' );
}

View 2 Replies View Related

Getting Status Code Back To 'system'

Aug 14, 2005

How do I get a status code returned from a shell script?

The following doesn't seem to work:

#!/bin/php
<?php
exit 5;
?>

View 2 Replies View Related

Server Status Code Not Working?

Jun 27, 2009

i am currently making a server status page for these private servers of this game. i have a PERFECT code thats got everything i need:PHP Code:

<?php
$live = "http://i44.tinypic.com/352fzow.png";
$dead = "http://i40.tinypic.com/15foej8.png";

[code]...

View 3 Replies View Related

Code To Find Status Of A Download?

Jul 5, 2010

Is there a simple code to find status of a download. For example, after I launch a file download with php, I want to find status of that download (whether its complete or not), just like file hosting/sharing sites do. And if its "in progress", I want to prevent parallel downloading. I don't understand much of header() commands, except header("location..."); "refresh:...

View 1 Replies View Related

Return A Respons Header To A Http Post

Aug 23, 2001

I want to return a respons header to a http post. The Http post is comming from a vb-program.

A xml document is posted, and I want to return a "Every thing is ok". How do I do that? Any tutorials?

View 8 Replies View Related

ADVERTISEMENT