473,503 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CURL to test if a URL exists

nathj
938 Recognized Expert Contributor
Hi,

I have developed a simple form, for site administration purposes so it is behind a user name and password check.

This form is to enable selected users to add external links to the list of useful links on our site. The form therefore has to take a URL. I have code to test that a URL has been supplied but then the next step is to make sure the URL actually exists.

I am trying to use CURL for this but so far nothing gives.
[PHP]
$lvCurlHandle = curl_init($lcLinkURL) ;
$lnHTPPCode = curl_getinfo($lvCurlHandle, CURLINFO_HTTP_CODE) ;
$loDebugObject->debugOutput("","","HTTP Code: " . $lnHTTPCode) ;
if($lnHTTPCode <> 200)
{
$lnErrorCount++ ;
$lcDisplay.= '<p class="warning">The URL supplied cannot be found</p>' ;
}
[/PHP]

So there's the code. I have been using the URL www.vtpad.co.uk for the variable $lcLinkURL which is coming over from the form.I know the URL exists because it's my test space for projects pre-launch.

What happens with that URL is the erro rmesasge comes out. I've tried outputting the HTTP code t see if that could shed any light on things but that is empty.

I figure I'm doing something wrong but re-reading over the manual and other sites I find nothing that sheds some light on the matter.

Does anyone have a pointer or two for me?

Many thanks
nathj
Oct 13 '08 #1
2 2516
Atli
5,058 Recognized Expert Expert
Hi.

You could try using the get_headers function instead.
It will attempt to fetch the headers of the given URL and return them as an array. If the page could not be read, the function returns FALSE and shows a warning.

Remember that putting a @ in front of a function like that should suppress any warnings it generates.
Oct 14 '08 #2
nathj
938 Recognized Expert Contributor
Hi.

You could try using the get_headers function instead.
It will attempt to fetch the headers of the given URL and return them as an array. If the page could not be read, the function returns FALSE and shows a warning.

Remember that putting a @ in front of a function like that should suppress any warnings it generates.
Atli,

Thank you for the tip. Following on from your pointer I have developed a little function on one of my objects;
[PHP]
function checkURL($pcURL, $pcReturnKey)
{
// check the supplied URL using the and return the value associated with the specified key
$laHeaders = @get_headers($pcURL, 1) ; // return the array with keys set

$lvReturn = $laHeaders[$pcReturnKey] ;
return $lvReturn ;
}
[/PHP]
All I do is call the method on the object and test the return.

This now works, I have tested with a good URL and a URL that is not registered.

Thank yo for your help. Not only I have solved this problem I have learned something new - and its only half 9 in the morning!

Cheers
nathj
Oct 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2683
by: machodev | last post by:
Hello Friends, Getting a bit fuzzy on the Authorize.net and the Curl Integration. I have the script using the for the authorize.net Integration with the curl command exec("/usr/local/bin -m...
1
2917
by: Haluk Durmus | last post by:
Hello I checked out openssl,mm,apr,apr-util,apache 2,curl,libxml and php from cvs. php couse an ERROR I did the following steps:
0
2463
by: Phil Powell | last post by:
What is the most standardized method of utilizing the CURL functions in PHP (version 4.3.2) to be able to retrieve the contents of a remote URL that happens to be dependent upon $_SESSION for its...
2
3156
by: TJ Talluto | last post by:
Hi, I'm using the curl functions in php to scrape the wan ip address from my home router (the router is an SMC product). This is a two step process: 1. post the password value to the login.htm...
3
6313
by: Chris Fortune | last post by:
# uname -a Linux stargate.mxc-online.net 2.4.20-021stab022.2.777-smp #1 SMP Wed Jul 28 17:12:37 MSD 2004 i686 i686 i386 GNU/Linux I recompiled PHP with mcrypt, openssl, and curl phpinfo():...
1
1854
by: lists04 | last post by:
Hi, I have a problem with a curl request and running it under popen2. If I run this request from the command line: curl -i http://www.yahoo.com/test --stderr errfile (also tried redirecting...
9
12562
by: Conrad F | last post by:
Hi, If any Microsoft people are listening.... Are there any plans for the new web language called "Curl" to be supported in .NET (ASP.NET)? I ask as Curl represents the first step to true OO...
1
1637
by: devranger | last post by:
Hello, I am in the process of learning PHP CURL and in doing some test examples I am having some issues with CURL that I do not fully understand. I am doing a test to use CURL to post and return...
12
7400
by: dkurth | last post by:
Hi, I'm running PHP 5.2.3 on Windows 2000 Server with IIS 5. I'm trying to get cUrl working, so in my php.ini file, I have this line: extension_dir ="F:\PHP\ext" And later, I have: ...
0
7205
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
7353
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...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5596
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,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
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...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.