Skip to content

Instantly share code, notes, and snippets.

@hipot
Last active August 22, 2026 13:53
Show Gist options
  • Select an option

  • Save hipot/7938e44b2a34b588bc97420e4851a9d7 to your computer and use it in GitHub Desktop.

Select an option

Save hipot/7938e44b2a34b588bc97420e4851a9d7 to your computer and use it in GitHub Desktop.
log 404 in content part
// log 404 in content part
$lastStatus = \CHTTP::GetLastStatus();
if ((constant('ERROR_404') == 'Y' || strpos($lastStatus, '404') !== false)
&& $APPLICATION->GetCurPage() != '/404.php'
) {
/*
CREATE TABLE `hi_seo_error404log` (
`ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
`UF_DATETIME` datetime DEFAULT NULL,
`UF_URL` text,
`UF_REFERER` text,
`UF_USER_AGENT` text,
`UF_ADDR` text,
PRIMARY KEY (`ID`),
KEY `IDX_DT` (`UF_DATETIME`)
);
*/
$error404TableEntity = Bitrix\Main\ORM\Entity::compileEntity('Error404LogTable', [
new Bitrix\Main\ORM\Fields\IntegerField('ID', [
'primary' => true
]),
new Bitrix\Main\ORM\Fields\DatetimeField('UF_DATETIME'),
new Bitrix\Main\ORM\Fields\TextField('UF_URL'),
new Bitrix\Main\ORM\Fields\TextField('UF_REFERER'),
new Bitrix\Main\ORM\Fields\TextField('UF_USER_AGENT'),
new Bitrix\Main\ORM\Fields\TextField('UF_ADDR'),
], [
'table_name' => 'hi_seo_error404log'
]);
$r = $error404TableEntity->getDataClass()::add([
'UF_DATETIME' => \Bitrix\Main\Type\DateTime::createFromTimestamp(time()),
'UF_URL' => $APPLICATION->GetCurPageParam("", [], false),
'UF_REFERER' => $_SERVER['HTTP_REFERER'], // . var_export($_SERVER, true),
'UF_USER_AGENT' => $_SERVER['HTTP_USER_AGENT'],
'UF_ADDR' => $_SERVER['REMOTE_ADDR']
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment