Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
A link validation script.
Old 07-20-2008, 02:52 AM A link validation script.
Junior Talker

Posts: 4
Trades: 0
Hi,

I have this link validation script that I got from some site. It works fine in testing enviornment i.e localhost, but when I upload it to my shared hosting account it did'nt work, here is the script,

function is_link_exist($url)
{
$host = parse_url($url, PHP_URL_HOST);
$path = parse_url($url, PHP_URL_PATH);

if (empty($path)) {
$path = "/";
}

/* build request headers
$reqh = "HEAD $path HTTP/1.1\r\n"
. "Host: $host\r\n"
. "Connection: Close\r\n\r\n";

$fp = @fsockopen($host, 80, $errno, $errmsg, 30);

if (!$fp) {
print "Sorry unable to connect.";
exit;
}

/* send request headers
fwrite($fp, $reqh);

/* read response
while(!feof($fp)) {
$resh .= fgets($fp, 4096);
}
fclose($fp);

/* get http status
$firstline = substr($resh, 0, strpos($resh, "\r\n"));
list($proto, $stat, $msg) = explode(" ", $firstline);

if ($stat == 200) {
return true;
}
else {
return false;
}
}

It prints out the "Sorry unable to connect" message, can any body help me out, or anybody has a working script?
aaddaa is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-20-2008, 03:06 AM Re: A link validation script.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
remove the @ from $fp = @fsockopen($host, 80, $errno, $errmsg, 30); so you can see the error message
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-20-2008, 04:56 AM Re: A link validation script.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
Most likely that sockets functions are disabled on your hosting. Try using curl extension.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 07-20-2008, 05:34 AM Re: A link validation script.
Junior Talker

Posts: 4
Trades: 0
Thanks mtishetsky,

I think so socket functions are disabled. Can you help me with curl extension. How to verify link using curl extensions? I googled but all the scripts I found use socket function to verfy links.

Thanks in advance.
aaddaa is offline
Reply With Quote
View Public Profile
 
Old 07-21-2008, 04:27 AM Re: A link validation script.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
$ch curl_init($url);
curl_setopt($chCURLOPT_NOBODY1);
curl_setopt($chCURLOPT_HEADER1);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
$res curl_exec($ch);

if (
preg_match('! 200 !m'$res)) {
   
$ok 1;

Something like that. Unfortunately curl cannot make http HEAD requests so you will have to pull the whole page.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to A link validation script.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21218 seconds with 12 queries