Check Whether a Page is 404 or not Using PHP
X

Congrats, You are Subscribed to Receive Updates.

Check Whether a Page is 404 or not Using PHP


Check Whether a Page is 404 or not Using PHP. Here in certain situations we need to know the page it whether 404 or not. Here I have some simple php codes to  find it through programmatically. Just use the following code to detect it yourself.

$kv_uri = 'https://www.kvcodes.com/testin-url-for-404-error' ; 
$kv_res = kv_get_page_title($kv_uri);

The above code will call a function with parameter of our url to check it.

function kv_get_page_title($url){
	
	$handle = curl_init($url);
	curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);
	$response = curl_exec($handle);
	$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
	if($httpCode == 404) {
		return true ; 
	} else {
		return false; 
	}
	curl_close($handle);
}

The above function will check the web page httpcode. If it returns 404 the error will be returned as true. Else it will return a false info.

if($kv_res == true) {
		
	echo  ' Yes its 404 Error Page' ; 
}else {
	echo ' No its working page'; 
		
}

That’s it . here is the full code for your usage.

<?php
// Program to check whether a page is 404 page or not.
$kv_uri = 'https://www.kvcodes.com/testin-url-for-404-error' ; 
$kv_res = kv_get_page_title($kv_uri);

if($kv_res == true) {
		
	echo  ' Yes its 404 Error Page' ; 
}else {
	echo ' No its working page'; 
		
}

function kv_get_page_title($url){
	
	$handle = curl_init($url);
	curl_setopt($handle,  CURLOPT_RETURNTRANSFER, TRUE);
	$response = curl_exec($handle);
	$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
	if($httpCode == 404) {
		return true ; 
	} else {
		return false; 
	}
	curl_close($handle);
}

?>

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

2 comments

  1. commenter

    Error
    SELECT `comment`
    FROM `phpmyadmin`.`pma__column_info`
    WHERE db_name = ‘fileeazy’
    AND table_name = ”
    AND column_name = ‘(db_comment)’
    MySQL said: Documentation

    #1932 – Table ‘phpmyadmin.pma__column_info’ doesn’t exist in engine

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts