473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

checking for broken URLs with PHP?

AK
Hi,

Can anyone tell me how to connect to a URL using PHP for the purpose
of obtaining the HTTP response code? Specifically, I want to be able
to ascertain whether a link is down (404) or alive.

A bare-bones example would be appreciated.

Thanks!

Nov 13 '07 #1
5 1117
On 13 Nov, 11:00, AK <danr...@gmail.comwrote:
Hi,

Can anyone tell me how to connect to a URL using PHP for the purpose
of obtaining the HTTP response code? Specifically, I want to be able
to ascertain whether a link is down (404) or alive.

A bare-bones example would be appreciated.

Thanks!
Try typing
php http request
into Google

Nov 13 '07 #2
On Nov 13, 8:00 am, AK <danr...@gmail.comwrote:
Hi,

Can anyone tell me how to connect to a URL using PHP for the purpose
of obtaining the HTTP response code? Specifically, I want to be able
to ascertain whether a link is down (404) or alive.

A bare-bones example would be appreciated.

Thanks!
Perhaps this could help

http://ar.php.net/manual/en/function.fopen.php#58099

Nov 13 '07 #3
On Nov 13, 12:00 pm, AK <danr...@gmail.comwrote:
....
Can anyone tell me how to connect to a URL using PHP for the purpose
of obtaining the HTTP response code? Specifically, I want to be able
to ascertain whether a link is down (404) or alive.

A bare-bones example would be appreciated.
<?php
file_get_contents("http://google.com");
var_dump($http_response_header);
?>
Csaba Gabor from Vienna

Nov 14 '07 #4
AK
On Nov 14, 12:09 am, Csaba Gabor <dans...@gmail.comwrote:
On Nov 13, 12:00 pm, AK <danr...@gmail.comwrote:
...
Can anyone tell me how to connect to a URL using PHP for the purpose
of obtaining the HTTP response code? Specifically, I want to be able
to ascertain whether a link is down (404) or alive.
A bare-bones example would be appreciated.

<?php
file_get_contents("http://google.com");
var_dump($http_response_header);
?>

Csaba Gabor from Vienna
Thanks, that's the sort of "quick solution" I was looking for
(although I managed to find it myself after a bit of digging:
$arr = get_headers("http://www.google.com");
is even more concise)

Thanks to the previous responses as well, including the one that
suggested using a quaint little thing that seems to have the amazing
ability to search through web pages! (Google, I think it's called... )

Cheers

Nov 14 '07 #5
In our last episode,
<11*********************@k79g2000hse.googlegroups. com>,
the lovely and talented AK
broadcast on comp.lang.php:
Hi,
Can anyone tell me how to connect to a URL using PHP for the purpose
of obtaining the HTTP response code? Specifically, I want to be able
to ascertain whether a link is down (404) or alive.
A bare-bones example would be appreciated.
Thanks!
Is there some reason searching the manual index on 'http' did not turn up
http_head for you?

--
Lars Eighner <http://larseighner.com/ <http://myspace.com/larseighner>
Countdown: 432 days to go.
What do you do when you're debranded?
Nov 15 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paris_Sucks | last post by:
I'm trying to redirect when testing for certain condidtions as shown below. When the conditions are ture, it redirects, but still goes ahead and processes the sql query. What am I doing wrong??? ...
6
by: Walter Dörwald | last post by:
Hello all! I'm trying to parse broken HTML with several Python tools. Unfortunately none of them work 100% reliable. Problems are e.g. nested comments, bare "&" in URLs and "<" in text (e.g....
1
by: Josef Meile | last post by:
Hi, I'm trying to do a simple link checking for python 2.1.3 (compiled from source on linux), but it fails when I use an invalid ssl url. For example: I have zope without ssl running on port...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
17
by: Christopher Benson-Manica | last post by:
All right, since my previous idea (calling functions through a wrapper) was apparently so awful no one could suggest any improvements, I'll try a different tack. My end goal is to make detecting...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
7
by: Dave | last post by:
Is it difficult to write a program that, given an array of URLs, will probe each one, and return a status of Found or Not Found? How would you approach it? While Googling, I found utility after...
5
by: Dave | last post by:
Hello All, A couple of weeks ago, I undertook to write a utility that would loop through various URLs and test whether they were valid. I got some good help from this list, and was able to...
8
by: Steve | last post by:
Hi Guys; You have been giving me a lot of useful information in the other two threads. Thanks! Very interesting. Here is my situation. My friend is writing a book. He has 3100 citations,...
1
by: rpupkin77 | last post by:
Hi, I have written this script to run as a cron that will loop through a text file with a list of urls. It works fine for most of the links, however there are a number of urls which are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.