WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : This gets the http response headers for a given url and returns them in an assoc array. i.e. to test if a url exists: $array = get_http_headers($url); if($array[result]=200) { }
Categories : HTTP, Arrays, PHP Update Picture
Mark Jeftovic
Date : Jan 17th 1999
Grade : 4 of 5 (graded 3 times)
Viewed : 7972
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Mark Jeftovic
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
//
// get_http_headers.php3 v1.1 1998/11/24
//
// Copyright (c) 1998 Mark Jeftovic / easyDNS Technologies Inc.
// email: markjr@easyDNS.com
//
// All rights reserved.
// This code provided "As Is" with no warrantees express or implied.
// The author and contributors are not liable for anything good or
// bad that results from your use of this code.
//
// You are free to distribute this for free provided this notice is
// included. Please forward fixes/enhancements to the author for
// inclusion in the next revision.
//
// USAGE: $array = get_http_headers.php3($url,$proto);
// $url is in the form http://www.somewhere
// $proto is optional default is HTTP/1.0
//
// RETURNS: an associative array with the keys set to the header name
// (lowercased) with the first line of headers (the result line)
// split up into:
// $array[result] = i.e. 200 or 301 or 403 or 404, etc
// $array[protocol] = protocol server used to answer
// $array[message] = i.e. "OK" or "FORBIDDEN" etc.
//
// HISTORY: 1.1 Nov 24/98
// -1 line fix from Gary E. Bickford, garyb@slb.com
// for when $uri[path] turns out to be null


function get_http_headers ($url,$proto= "HTTP/1.0") {

if(!eregi( "^http://", $url)) { $url = "http://".$url; }
$uri = parse_url($url);
$port = ( $uri[ "port"] ? $uri[ "port"] : 80 );
# open a socket to the server
$sock = fsockopen($uri[host],$port);
if(!$sock) { return(-1); }
if (!strlen($uri[path])) {$uri[path] = "/";}
$req=sprintf( "HEAD %s %s\n\n", $uri[path], $proto);

# send the request
fputs($sock, $req);

# get the headers
while(!feof($sock)):
$this_out = fgets($sock,100);
$output.= $this_out;
endwhile;
fclose($sock);

# parse them into a hash
$hdr=split( "\n",$output);
list($array[ "protocol"], $array[ "result"], $array[ "message"]) = split("[[:space:]]+", $hdr[0], 3);

for($i=1,$num=count($hdr);$i<$num;$i++) {
list($key, $val)=split( ":[[:space:]]*", $hdr[$i],2);
$array[strtolower($key)]=$val;

}

return($array);
}
?>



The following snippet gives complete info about all submitted HTTP_POST_VARS and HTTP_GET_VARS
Categories : Variables, HTTP, PHP
clearing variables in php3
Categories : Variables, Arrays, PHP
Select with current month
Categories : PHP, HTML and PHP, Date Time, Arrays
Simple Password example
Categories : PHP, Authentication, Security, HTTP
Stock quotes from yahoo!
Categories : PHP, Web Services, Arrays
How to display any array in several rows and columns of a table. Not just in one column or in alternate rows. This example shows a nice color table generated with PHP, but can be used with any array values(e.g. Database)
Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics
Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays
translate.php - Assocciative array example, passing a reference to a function.
Categories : PHP, Arrays, Languages, Variables
Finds the median in an array of numbers - Can be used with a MySql database column read into an array
Categories : PHP, Arrays, Databases, MySQL
header -- Send a raw HTTP header
Categories : PHP, PHP Functions, HTTP
XML To Array
Categories : PHP, PHP Classes, XML, Arrays
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Array values from javascript to php
Categories : PHP, Java Script, Arrays
 Steve Doty wrote :1
Cool example.
 Almost what I needed, I wanted something that returns the
content-length & content-type also.
To do that I had to replace the dash '-' char to a underscore 
'_' in the $key value.$array[] can not use dashes in val names.
Without this you can not return content-length or content-type.
you can add a str_replace call.
$strkey = str_replace("-","_",$key);

in this 'for' statment to fix it.

        for($i=1,$num=count($hdr);$i<$num;$i++) {
                 list($key, $val)=split(  ":[[:space:]]*", $hdr[$i],2);
                $strkey = str_replace("-","_",$key);
                 $array[strtolower($strkey)]=$val;
                 }