301 Moved Permanently Script

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
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

301 Moved Permanently Script

Post by Mr Tech »

I want to write a script that cheks whether the URL they entered is "301 Moved Permanently".

What code would I need to find out if its a 301 redirect page?

Cheers
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

Code: Select all

<?php

$moved_permanent = false;

$url = 'http://foo.com';

$fp = fopen($url, 'r');

foreach ($http_response_header as $header) {
    if (false !== strpos($header, '301')) {
        $moved_permanent = true;
        break;
    }
}

?>
yes, the variable $http_response_header appears out of thin air
Post Reply