1) I am using wordpress engine. 2) I have an numeric array() with 800+ links in it, like this.
What I'm trying to do is to run foreach() function and check if link still exist (not returning 404 error).
I tried 2 functions:
1)
<?php
foreach($links as $link) {
$file_headers = @get_headers($link);
if(strpos($file_headers[0],'404') === false) {
$toDeleteLinks[] = $link;
}
}
?>
so according to this first function, $toDeleteLinks array should contain all the links that return 404 error. using get_headers() functions here...
2)
<?php
foreach($links as $link) {
$handle = curl_init($link);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($httpCode != 404) {
$toDeleteLinks[] = $link;
}
curl_close($handle);
}
?>
this second one should do the same just using cURL..
BUT in both cases I get redirected to the wordpress 404.php page ((. I think that's because of a big number of links.
Can you please help me get a solution for this? Use another function instead or however...
Thanks.