Get <title> HTTP request failed! HTTP/1.0 403 Forbidden

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gth759k
Forum Commoner
Posts: 76
Joined: Mon Jun 15, 2009 3:04 am

Get <title> HTTP request failed! HTTP/1.0 403 Forbidden

Post by gth759k »

I need to get the <title> from any given url, and my script works fine normally but sometimes I come across a page that give me a 403 error and it won't grab the title. Any suggestions? The errors I get when I change the code around all have HTTP request failed! HTTP/1.0 403 Forbidden in them.

Here's my script:

Code: Select all

$file = @file_get_contents($link);

if(preg_match("/<title>(.+)<\/title>/i",$file,$m)) {
	$title = $m[1];
	$title = strip_tags(addslashes(trim(preg_replace("/&#?[a-z0-9]{2,8};/i","",$title))));
}
else {
	$title = '';
}
Post Reply