473,657 Members | 2,437 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($lcLi nkURL) ;
$lnHTPPCode = curl_getinfo($l vCurlHandle, CURLINFO_HTTP_C ODE) ;
$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 2528
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($p cURL, 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
2699
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 120 -d \"$data\" $authnet_url", $return_string); well the curl path is right /usr/local/bin/
1
2927
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
2478
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 content display? I've tried the following class methods for display and I have most everything working until I get to a URL that requires $_SESSION: class Timer extends View {
2
3161
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 page 2. capture and parse the content from the status_main.htm page On the SMC's login.htm page there is a form with the following elements: <form name=tF method=post action=login.htm> <input type=password name=pws> <input type=hidden...
3
6323
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(): http://www.canadiandropshipping.com/hello.php3 Does anyone know why this ssl curl test fails? http://www.canadiandropshipping.com...t/diag_curl.php
1
1862
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 stdderr to a file 2>, nothing) the file errfile is empty indicating no error with the request. However, when I do something similar in python:
9
12586
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 programming of web pages and not just running "scripts" which have in-roads into service DLLs of other languages such as C#. Surely MS will put Curl into .NET at some time since it is designed to work with DirectX and OpenGL?
1
1642
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 results from "http://powersports.honda.com/dealer_locator/dealer_locator.asp" However it does not appear to be returning results from the CURL post action. What CURL appears to be doing is finding the page...
12
7436
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: extension=php_curl.dll
0
8826
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
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6166
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4155
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
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
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.