28, May 2012

return http_code with cURL - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: return http_code with cURL
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: return http_code with cURL  (Read 5255 times)
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« on: Sep 11, 2006, 03:22:01 pm »

Just a simple function to return the http code (404, 200, 301 etc.)

Code:
<?php
function get_link_header($aUrl) {
if (preg_match("/^http:\/\//",$aUrl)) {
$ch curl_init();
curl_setopt($chCURLOPT_URL$aUrl);
curl_setopt($chCURLOPT_HEADER1);
curl_setopt($chCURLOPT_NOBODY1);
curl_setopt($chCURLOPT_FOLLOWLOCATION1);
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_TIMEOUT30);
curl_exec($ch);
$info curl_getinfo($ch);
curl_close ($ch);
if (!empty($info)) {
return $info['http_code'];
} else {
return 0;
}
} else {
return 0;
}
}


I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: Sep 11, 2006, 05:21:34 pm »

Nice snippet.

BTW I think that this directive :

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

is not needed. Feel free to post that to the codex library Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #2 on: Sep 11, 2006, 08:52:54 pm »

Nice snippet.

BTW I think that this directive :

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

yes, this is need otherwise the whole deaher is returned (I thought the same)Wink

I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #3 on: Sep 12, 2006, 07:53:04 am »

lol Smiley

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=4036
Tags : curl snippets Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: return http_code with cURL
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 04:26:56 pm





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.