Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc
Comunitatea PHP Romania
 

HTTP Status Code
Vezi mesajul original

 
       Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc -> PHP Avansat
Subiectul anterior :: Subiectul următor  
Autor Mesaj
bond



Data înscrierii: 15/Dec/2004
Mesaje: 201

Trimis: Mie Aug 10, 2005 7:56 pm    Titlul subiectului: HTTP Status Code  

Stie cineva cum se poate obtine valoarea lui HTTP Status Code prin functii de PHP4? (ex: codul 200=OK, codul 301=Moved Permanently, etc.)
In PHP5 il gasesc in primul element din array-ul returnat de get_headers().
Sus  
Pirahna



Data înscrierii: 22/Aug/2004
Mesaje: 4558
Locație: la birou

Trimis: Mie Aug 10, 2005 8:56 pm    Titlul subiectului:  

mai ... eu altceva nu prea am gasit (sau poate ca m-am tampit si nu mai stiu sa caut ?)

http://ro.php.net/header

:?
Sus  
bond



Data înscrierii: 15/Dec/2004
Mesaje: 201

Trimis: Mie Aug 10, 2005 9:07 pm    Titlul subiectului:  

Cu header() creezi un header. Eu vreau sa citesc din el.

Vreau sa obtin ce iti afiseaza extensia Web Developer din Firefox in tagul Information la View Response Headers, mai precis ultimul rind.
Cod: Response Headers - http://www.phpromania.net/forum/viewtopic.php?p=17322#17322

Date: Wed, 10 Aug 2005 19:08:27 GMT
Server: Apache/1.3.33 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 PHP/4.3.11 FrontPage/5.0.2.2635 mod_ssl/2.8.22 OpenSSL/0.9.7a
X-Powered-By: PHP/4.3.11
Set-Cookie: phpbb2mysql_t=a; path=/; domain=www.phpromania.net
Cache-Control: private, pre-check=0, post-check=0, max-age=0
Expires: 0
Pragma: no-cache
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html

200 OK
Sus  
whooper



Data înscrierii: 05/Apr/2005
Mesaje: 727
Locație: Toronto ON

Trimis: Joi Aug 11, 2005 5:36 am    Titlul subiectului:  

get_headers

(PHP 5)
get_headers -- Fetches all the headers sent by the server in response to a HTTP request
Description
array get_headers ( string url [, int format] )

get_headers() returns an array with the headers sent by the server in response to a HTTP request. Returns FALSE on failure.

If the optional format parameter is set to 1, get_headers() parses the response and sets the array's keys.

Example 1. get_headers() example Cod:
<?php
$url = 'http://www.example.com';

print_r(get_headers($url));

print_r(get_headers($url, 1));
?>

sau daca n-ai php 5

Cod:
<?php
if (isset($_POST['url']) && get_magic_quotes_gpc()) {
    $_POST['url'] = stripslashes($_POST['url']);
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Fetch HTTP Headers</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Fetch HTTP Headers</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p><label for="url">URL:</label><br />
<input name="url" id="url" type="text" value="<?php echo isset($_POST['url']) ? htmlentities($_POST['url']) : 'http://www.example.com/'; ?>" /></p>

<p><input type="submit" name="submit" value="Fetch" /></p>
<?php

if (isset($_POST['submit'])) {
    $url_array = parse_url(trim($_POST['url']));
    $port      = isset($url_array['port']) ? $url_array['port'] : 80;
    $handle    = @fsockopen($url_array['host'], $port, $errno, $errstr, 30);

    if ($handle) {
        $path  = isset($url_array['path']) ? $url_array['path'] : '/';
        $query = isset($url_array['query']) ? '?' . $url_array['query'] : '';

        $request  = 'HEAD ' . $path . $query . ' HTTP/1.0' . "\r\n";
        $request .= 'Host: ' . $url_array['host'] . "\r\n";
        $request .= 'Connection: close' . "\r\n\r\n";

        fwrite($handle, $request);

        while (!feof($handle)) {
            $header_array[] = trim(fgets($handle));
        }

        echo '<h2>Request</h2>' . "\n";
        echo '<pre>' . trim($request) . '</pre>' . "\n";
        echo '<h2>Response</h2>' . "\n";
        echo '<pre>' . trim(implode("\n", $header_array)) . '</pre>' . "\n";

        fclose($handle);
    } else {
        echo '<p>Socket connection could not be established. URL may be invalid.</p>' . "\n";
        echo '<!-- ' . $errstr . ' (' . $errno . ') -->' . "\n";
    }
}

?>
Sus  
bond



Data înscrierii: 15/Dec/2004
Mesaje: 201

Trimis: Joi Aug 11, 2005 3:02 pm    Titlul subiectului:  

@whooper:
Mersi
Sus  
Zamolxe



Data înscrierii: 14/Ian/2003
Mesaje: 126
Locație: Bucharest

Trimis: Sâm Aug 27, 2005 9:32 am    Titlul subiectului: re  

cu get_headers am avut mai multe probleme, recomand urmatoarea abordare:

$host = "www.phpromania.net";
$path = "/";

Cod:
$fp = fsockopen($host, 80, $errno, $errstr, 5); //deschid conexiune pe port 80
if (!$fp) {
   print "EROARE: $errstr ($errno)\n";
   return false;
} else {
   $out = "GET ".$path." HTTP/1.1\r\n";
   $out .= "Host: ".$host."\r\n";
   $out .= "User-Agent: Mozilla/5.0 (compatible)\r\n";
   $out .= "Content-type: text/html\r\n";
   $out .= "Accept-Charset: iso-8859-1\r\n";
   $out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
//verificam headerele documentului
for($i=0;$i<=7;$i++){ //luam primele 7-8 linii din document care contin headerul
   $html_header .= fgets($fp, 128);
}
//verificare daca headerul contine HTTP
if(ereg("HTTP/[0-9.]+ (([0-9])[0-9]{2})", $html_header, $regs)){
   //print_r($regs);
[...]
Sus  
PHPRomania Bot
Bot Member


Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google
Trimis: Mie Dec 26, 2007 7:01 pm   Titlul subiectului: Ad  

Sus  
 
       Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc -> PHP Avansat
Pagina 1 din 1


Powered by phpBB 2.0.22 © 2001, 2002 phpBB Group
Varianta în limba română: Romanian phpBB online community