473,775 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1125
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_conten ts("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_conten ts("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("ht tp://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************ *********@k79g2 000hse.googlegr oups.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
5612
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??? And then sometimes when the conditions are correct, it doens't redirect. It appears to be very inconsistent. Any suggestions would be greatly appreciated. //Check for repeat name $result = mysql_query("SELECT * FROM survey WHERE FirstName =
6
2004
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. "if foo < bar") etc. All of these pages can be displayed properly in a browser so why not reuse the parser in e.g. Mozilla? Is there any way to get proper XML out of Mozilla? Calling mozilla on the
1
2116
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 8080, if I do this on the browser's address bar: https://my_ip:8080 --> The https is intentional mozilla on linux and IE on windows, take a long time till a timeout
67
4283
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. Unfortunately these ad hominem rhetorts are frequently introduced into purely technical discussions on the feasibility of supporting such functionality in C++. That usually serves to divert the discussion from the technical subject to a discussion of the...
17
2735
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 and reporting script errors easy and painless. This could be accomplished easily if window.onerror were ubiquitous, but it is not. My new idea is to hack together something superficially resembling C's assert() macro, perhaps something like ...
30
2254
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; return NULL; }
7
1818
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 utility that will do something like that for you, but I would like to write a custom program to do this. It doesn't have to be VB. C#, javascript, etc. - whatever will run on .NET. Thanks in advance,
5
998
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 write the utility. Now, I have run into a problem that is difficult for me to solve. It is this: When looping through a large set of URLs, if many of the URLS are bad, the program will time out. Conversely, if most of the URLs are good, it will...
8
1847
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, 1225 of which have URLs. He wants to Q/C the urls. He removed the http:// from the urls when he prepared his materials. I wrote a script that extracted the citation number and the urls from his citation list, prepended an "http", and
1
1055
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 subdomains (they are government sites) such as http://basename.airforce.mil, these links are always throwing 400 errors even though the site exists. Is there a way to get around this?
0
9622
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9916
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5360
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.